MATLAB error assigning values

4 Ansichten (letzte 30 Tage)
Buddhini Angelika
Buddhini Angelika am 24 Jan. 2016
Beantwortet: Steven Lord am 24 Jan. 2016
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 Kommentar
Stephen23
Stephen23 am 24 Jan. 2016
@Buddhini Angelika: please edit your question and upload your code: click the paperclip button, then both the Choose file and Attach file buttons.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Steven Lord
Steven Lord am 24 Jan. 2016
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.

Kategorien

Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by