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:
An array problem

Subject: An array problem

From: ali kucur

Date: 16 Dec, 2012 14:56:17

Message: 1 of 7

A=[1 2 3 4 5 6 7 8];
satir=4;
sutun=length(A)/4;
>> B=reshape(A, sutun, satir);
>> for (i=1:sutun)
d(i)=B(i,:);
end
ans=[d(i)]


I m getting the error shown below, please help me folks.

In an assignment A(I) = B, the number of elements in B and I must be the same.

Subject: An array problem

From: Roger Stafford

Date: 16 Dec, 2012 15:40:21

Message: 2 of 7

"ali kucur" <kobay000@gmail.com> wrote in message <kakneh$cjo$1@newscl01ah.mathworks.com>...
> A=[1 2 3 4 5 6 7 8];
> satir=4;
> sutun=length(A)/4;
> >> B=reshape(A, sutun, satir);
> >> for (i=1:sutun)
> d(i)=B(i,:);
> end
> ans=[d(i)]
>
>
> I m getting the error shown below, please help me folks.
>
> In an assignment A(I) = B, the number of elements in B and I must be the same.
- - - - - - - - -
  Your error message is telling you what is wrong. You are trying to stuff four numbers into a single entry of the 'd' array and they won't fit!

Roger Stafford

Subject: An array problem

From: ali kucur

Date: 16 Dec, 2012 17:20:21

Message: 3 of 7

"Roger Stafford" wrote in message <kakq15$jgd$1@newscl01ah.mathworks.com>...
> "ali kucur" <kobay000@gmail.com> wrote in message <kakneh$cjo$1@newscl01ah.mathworks.com>...
> > A=[1 2 3 4 5 6 7 8];
> > satir=4;
> > sutun=length(A)/4;
> > >> B=reshape(A, sutun, satir);
> > >> for (i=1:sutun)
> > d(i)=B(i,:);
> > end
> > ans=[d(i)]
> >
> >
> > I m getting the error shown below, please help me folks.
> >
> > In an assignment A(I) = B, the number of elements in B and I must be the same.
> - - - - - - - - -
> Your error message is telling you what is wrong. You are trying to stuff four numbers into a single entry of the 'd' array and they won't fit!
>
> Roger Stafford


i wonder can you tell me what should it like be ?

Subject: An array problem

From: Roger Stafford

Date: 16 Dec, 2012 19:17:26

Message: 4 of 7

"ali kucur" <kobay000@gmail.com> wrote in message <kakvsl$5oj$1@newscl01ah.mathworks.com>...
> i wonder can you tell me what should it like be ?
- - - - - - -
  It is up to you to determine what you wish to accomplish, always remembering that you can't put more than one number into a single array position. Tell us what size or sizes the 'd' array is supposed to have and what each position is to contain after your operation is finished.

Roger Stafford

Subject: An array problem

From: ali kucur

Date: 16 Dec, 2012 22:25:08

Message: 5 of 7

"Roger Stafford" wrote in message <kal6o6$ntk$1@newscl01ah.mathworks.com>...
> "ali kucur" <kobay000@gmail.com> wrote in message <kakvsl$5oj$1@newscl01ah.mathworks.com>...
> > i wonder can you tell me what should it like be ?
> - - - - - - -
> It is up to you to determine what you wish to accomplish, always remembering that you can't put more than one number into a single array position. Tell us what size or sizes the 'd' array is supposed to have and what each position is to contain after your operation is finished.
>
> Roger Stafford

'd' array's size equal to "sutun". for example if sutun=4 then the process must be:

d1=B(1,:);
d2=B(2,:);
d3=B(3,:);
d4=B(4,:);
ans=[d1 d2 d3 d4]

but "sutun" has variable value so i want to make it universal for each "sutun" value. hope i could explain what is the goal, thanks in advance.

Subject: An array problem

From: Roger Stafford

Date: 17 Dec, 2012 00:01:29

Message: 6 of 7

"ali kucur" <kobay000@gmail.com> wrote in message <kalho4$nug$1@newscl01ah.mathworks.com>...
> 'd' array's size equal to "sutun". for example if sutun=4 then the process must be:
>
> d1=B(1,:);
> d2=B(2,:);
> d3=B(3,:);
> d4=B(4,:);
> ans=[d1 d2 d3 d4]
>
> but "sutun" has variable value so i want to make it universal for each "sutun" value. hope i could explain what is the goal, thanks in advance.
- - - - - - - -
  The code you tried is invalid in matlab. To get to the result you show, do it this way:

 D = reshape(reshape(A,p,q).',1,[]);

Roger Stafford

Subject: An array problem

From: ali kucur

Date: 17 Dec, 2012 18:21:05

Message: 7 of 7

"Roger Stafford" wrote in message <kalncp$a3b$1@newscl01ah.mathworks.com>...
> "ali kucur" <kobay000@gmail.com> wrote in message <kalho4$nug$1@newscl01ah.mathworks.com>...
> > 'd' array's size equal to "sutun". for example if sutun=4 then the process must be:
> >
> > d1=B(1,:);
> > d2=B(2,:);
> > d3=B(3,:);
> > d4=B(4,:);
> > ans=[d1 d2 d3 d4]
> >
> > but "sutun" has variable value so i want to make it universal for each "sutun" value. hope i could explain what is the goal, thanks in advance.
> - - - - - - - -
> The code you tried is invalid in matlab. To get to the result you show, do it this way:
>
> D = reshape(reshape(A,p,q).',1,[]);
>
> Roger Stafford


thanks s lot sir you just make my day :)

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