How to build x and y coordinates using a For loop

15 visualizaciones (últimos 30 días)
leydy Garcia
leydy Garcia el 20 de Feb. de 2020
Comentada: leydy Garcia el 20 de Feb. de 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?

Respuesta aceptada

Fangjun Jiang
Fangjun Jiang el 20 de Feb. de 2020
Editada: Fangjun Jiang el 20 de Feb. de 2020
maybe it should be
y=zeros(12,2)
x(i,:)=[x1(i),x2(i)];
y(i,:)=[y1(i),y2(i)];

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by