MATLAB Answers


saving value in matfile

Asked by Elysi Cochin on 8 Mar 2013

i did some calculation and got a variable 'binr' with 1 row and many column values( more than 800)....

i wanted to save it in a matfile in a format, so that i can contain values only upto 25 coulmns in one row.... so i wrote the code as

 binr = reshape(binr,25,[]).';

but if binr is not divisible by 25 i'm getting error as

    ??? Error using ==> reshape
    Product of known dimensions, 25, not divisible into total number of elements, 871.
    Error in ==> Todel at 176
    binr = reshape(binr,25,[]).';

What can i do to store the value of this variable in a matfile with only 25 columns even if the value in binr is not divisible by 25..... is it possible.... please do reply....


Do you want to throw away the extras, or do you want to pad to make up a full line ?

dont throw away extras sir....

it should have minimum 25 rows 25 columns..... if more than that only 25 columns but any number of rows..... if less than 25 rows 25 columns add some pattern.....

is it possible to add a pattern like "0 0 1 1 0 0" or " 1 1 1 0 0" or some fill the remaining rows and columns..... but how to do that sir.....

please do reply sir......



No products are associated with this question.

1 Answer

Answer by Walter Roberson
on 8 Mar 2013
 Accepted answer

fillpat = repmat([0 0 1 1], 1, 6]);
binr = reshape( [binr, fillpat(1 : mod(-length(binr),25))], 25, []) .';


sir what if i want minimum of 25 rows and 25 columns..... how to satisfy that condition also....

binr( end+1 : 25, :) = repmat( [fillpat, 0], max(0, 25 - size(binr,1)), 1);

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!