MATLAB error assigning values

조회 수: 3 (최근 30일)
Buddhini Angelika
Buddhini Angelika 2016년 1월 24일
답변: Steven Lord 2016년 1월 24일
I have a matlab gui made using MATLAB R2013a which computes a value u2 and also it performs the following computations:
n2=u2+1;
J1=HA(1);J2=HA(2);where HA is a vector with two values,
F=zeros(1,n2); T=zeros(1,n2);
Then after under going some computations in a loop I assign the value J1 to the first position of vector F by the command
F(1)=J1; and also some other values to other positions. But then it gives the following error:
_ _ _ *In an assignment A(I) = B, the number of elements in B and I must be the same.
Error in Communication_using_ECC_Receiver>pushbutton4_Callback (line 566) F(1)=J1;F(2)=J12G;F(n2)=0;
Error in gui_mainfcn (line 96) feval(varargin{:});
Error in Communication_using_ECC_Receiver (line 44) gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)Communication_using_ECC_Receiver('pushbutton4_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback*___
I can not understand the error. I thought we can replace the values in any vector by some other value by using commands like F(1)=J1;. Can some one please explain me what's the error here and also please tell me a way to overcome the error and obtain the result as required by assigning values replacing the old value in the vector.
Please help me with this problem.
Thanks a lot in advance.
  댓글 수: 1
Stephen23
Stephen23 2016년 1월 24일
@Buddhini Angelika: please edit your question and upload your code: click the paperclip button, then both the Choose file and Attach file buttons.

댓글을 달려면 로그인하십시오.

답변 (1개)

Steven Lord
Steven Lord 2016년 1월 24일
Since F(1) refers to one element in F, the data you assign into F(1) must have exactly one element as well. Something like the following won't work, since you can't fit 2 elements (on the right side) into 1 element (on the left.)
F(1) = [1 2]
So set a breakpoint on the line where you try to assign J1 into F(1) and see how many elements J1 has when MATLAB reaches that breakpoint.

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by