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 matrix/array

Subject: create matrix/array

From: Ondrej

Date: 23 Mar, 2009 22:39:01

Message: 1 of 3

Hi Guys,

I would need a help with creating a matrix/array which is going to have 18 columns and 76 rows,… first 4 rows are “0”, next 4 rows are “5”, next 4 rows are “10” and so on the last 4 rows are “90”,…. for this I wrote the following script:

row1 = 1:4:76;
row2 = 0:5:90;
 
 for ii =1:1:size(row1,2);
   for jj = 1:1:size(row2,2);
          
b(row1(ii),:)= (row2(jj))*ones(1,18);
b((row1(ii)+1),:)= (row2(jj))*ones(1,18);
b((row1(ii)+2),:)= (row2(jj))*ones(1,18);
b((row1(ii)+3),:)= (row2(jj))*ones(1,18);
 
    end
end


but it gives “90” in all 76x18 cells for reason I don’t see,… there must be some problem with jj loop?

Many thanks for the help
Ondrej

Subject: create matrix/array

From: Roger Stafford

Date: 23 Mar, 2009 23:41:01

Message: 2 of 3

"Ondrej " <ondrej.muransky@ansto.gov.au> wrote in message <gq9325$2iv$1@fred.mathworks.com>...
> Hi Guys,
>
> I would need a help with creating a matrix/array which is going to have 18 columns and 76 rows,… first 4 rows are “0”, next 4 rows are “5”, next 4 rows are “10” and so on the last 4 rows are “90”,…. for this I wrote the following script:
>
> row1 = 1:4:76;
> row2 = 0:5:90;
>
> for ii =1:1:size(row1,2);
> for jj = 1:1:size(row2,2);
>
> b(row1(ii),:)= (row2(jj))*ones(1,18);
> b((row1(ii)+1),:)= (row2(jj))*ones(1,18);
> b((row1(ii)+2),:)= (row2(jj))*ones(1,18);
> b((row1(ii)+3),:)= (row2(jj))*ones(1,18);
>
> end
> end
>
>
> but it gives “90” in all 76x18 cells for reason I don’t see,… there must be some problem with jj loop?
>
> Many thanks for the help
> Ondrej

  An exercise in 'repmat' and 'reshape':

 b = repmat(reshape(repmat(0:5:90,4,1),[],1),1,18);

Roger Stafford

Subject: create matrix/array

From: Ondrej

Date: 24 Mar, 2009 00:30:18

Message: 3 of 3

Hi Roger,

many thanks for your help, I would never come with such simple solution,...
cheers, ondrej

Tags for this Thread

No tags are associated with 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