How to build x and y coordinates using a For loop
13 views (last 30 days)
Show older comments
leydy Garcia
on 20 Feb 2020
Commented: leydy Garcia
on 20 Feb 2020
Hi. I want to plot a series of lines using x and y data extracted from a uitable. But I am having some error regarding the dimension of x and y. Here is the code:
x1=zeros(12,1);
x2=zeros(12,1);
y1=zeros(12,1);
y2=zeros(12,1);
x=zeros(12,2);
y=zeros(12,1);
for i=1:12
x1(i)=str2double(data(i,4));
x2(i)=str2double(data(i,4));
y1(i)=str2double(data(i,2));
y2(i)=str2double(data(i,3));
x(i)=[x1(i),x2(i)];
y(i)=[y1(i),y2(i)];
l=plot(handles.axes4,x(i),y(i));
axis(handles.axes4,'ij');
end
The error is the following:
In an assignment A(I) = B, the number of elements in B and I must be the same.
Error in Loading_Well_logs>pushbutton6_Callback (line 1898)
x(i)=[x1(i),x2(i)];
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in Loading_Well_logs (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)Loading_Well_logs('pushbutton6_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
Could somebody tell me what I am doing wrong?
0 Comments
Accepted Answer
Fangjun Jiang
on 20 Feb 2020
Edited: Fangjun Jiang
on 20 Feb 2020
maybe it should be
y=zeros(12,2)
x(i,:)=[x1(i),x2(i)];
y(i,:)=[y1(i),y2(i)];
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!