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

Thread Subject:
Create irregular matrix

Subject: Create irregular matrix

From: Ag

Date: 17 Oct, 2008 18:33:02

Message: 1 of 4

Hello guys,


How do I fit a vector of 97 elements in a matrix of 10x10??

Because of missing values the last values of the first 3 columns are NaN and the rest of the cells must be filled woth my vector.

I have already created a 10*10 matrix woth NaN values and I am just trying to reshape the vector in the matrix but I don?t know how. And the HELP does not contain a clear exmaple of what I want.

Any suggestions??

Thanks

Ag

Subject: Create irregular matrix

From: matt dash

Date: 17 Oct, 2008 18:38:02

Message: 2 of 4

"Ag " <ag@gmail.com> wrote in message <gdalou$19o$1@fred.mathworks.com>...
> Hello guys,
>
>
> How do I fit a vector of 97 elements in a matrix of 10x10??
>
> Because of missing values the last values of the first 3 columns are NaN and the rest of the cells must be filled woth my vector.
>
> I have already created a 10*10 matrix woth NaN values and I am just trying to reshape the vector in the matrix but I don?t know how. And the HELP does not contain a clear exmaple of what I want.
>
> Any suggestions??
>
> Thanks
>
> Ag

I believe this will do it:

A=rand(1,97);
B=nan(10,10);
B(1:97)=A;

you might need to transpose B if you want it the other way around.

Subject: Create irregular matrix

From: Ashish Uthama

Date: 17 Oct, 2008 19:15:00

Message: 3 of 4

help reshape

>> a=1:97;
>> b=reshape([a,nan(1,3)],10,10);
>> whos
   Name Size Bytes Class Attributes

   a 1x97 776 double
   b 10x10 800 double

>>




On Fri, 17 Oct 2008 14:33:02 -0400, Ag <ag@gmail.com> wrote:

> Hello guys,
>
>
> How do I fit a vector of 97 elements in a matrix of 10x10??
>
> Because of missing values the last values of the first 3 columns are NaN
> and the rest of the cells must be filled woth my vector.
>
> I have already created a 10*10 matrix woth NaN values and I am just
> trying to reshape the vector in the matrix but I don?t know how. And the
> HELP does not contain a clear exmaple of what I want.
>
> Any suggestions??
>
> Thanks
>
> Ag

Subject: Create irregular matrix

From: Walter Roberson

Date: 17 Oct, 2008 19:34:28

Message: 4 of 4

matt dash wrote:
> "Ag " <ag@gmail.com> wrote in message <gdalou$19o$1@fred.mathworks.com>...

>> Because of missing values the last values of the first 3 columns are NaN and the rest of
>> the cells must be filled woth my vector.

> I believe this will do it:
 
> A=rand(1,97);
> B=nan(10,10);
> B(1:97)=A;

No, in that scheme, the final three -rows- of the final column would be nan,
rather than the last values of the first three -columns-

B = nan(10,10);

nidxes = numel(B) - size(B,2) + (1:3); %if first 3 rows nan
OR
nidxes = numels(B) - 3 + (1:3)); %if last 3 rows nan


B(~ismember(1:numel(B),nidxes)) = A; %if to fill down the columns

I'm stuck at the moment for a one-liner that would fill across the rows instead.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us