how should i put the data in gui uitable
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
alireza kooshafar
el 14 de Nov. de 2015
Editada: alireza kooshafar
el 15 de Nov. de 2015
hey, i am beginer in GUI and i have written this code in gui which i used 2 uitable and in first one the user should enter all data for columns number 1 and 3 and just first cell of columns 2, 10 and 11 and put sum of spitial culomns in uitable 2. but i have evaluating eror in this push buttom. thank for help.
data = get(handles.ut1,'Data');
A = data(:,1);
[m n]=size(A);
G = zeros(m,n);
G(1) = data (1,2);
for i=2:m
G(i)=G(i-1)+A(i-1)-180;
if G(i)>360
G(i)=G(i)-360;
elseif G(i)<0
G(i)=G(i)+360;
end
end
d = data(:,3);
deltax = zeros(m,n) ;
deltay = zeros(m,n) ;
cx=zeros(m,n) ;
cy=zeros(m,n) ;
deltaxc = zeros(m,n) ;
deltayc = zeros(m,n) ;
for i = 1:m ;
G(i)=G(i)*(pi/180);
deltax(i)=d(i)*sin(G(i));
deltay(i)=d(i)*cos(G(i));
cx(i)=(-d(i))*(sum(deltax)/sum(d));
cy(i)=(-d(i))*(sum(deltay)/sum(d));
deltaxc(i)=deltax(i)+cx(i);
deltayc(i)=deltay(i)+cy(i);
end
x=zeros(m,n);
y=zeros(m,n);
x(1) = data (1,10);
y(1) = data (1,11);
for i=2:m;
x(i)= x(i-1)+deltaxc(i-1);
y(i)= y(i-1)+deltayc(i-1);
end
res = [A, G ,d, deltax, deltay, cx ,cy, deltaxc, deltayc ,x, y];
set(handles.ut1,'Data',res)
1 comentario
Respuesta aceptada
Walter Roberson
el 14 de Nov. de 2015
One thing that you need to keep in mind is that the Data property for a uitable is normally a cell array, so that a uitable may have data in multiple formats. However it is also allowed for the Data property to be a numeric array. Your code has been written under the assumption that you will always be dealing with a numeric array. That is not exactly wrong but it is a bit fragile. You would be safer checking whether you had a cell array with iscell() and using cell2mat() if it is a cell.
3 comentarios
Walter Roberson
el 14 de Nov. de 2015
data = get(handles.ut1,'Data');
if iscell(data); data = cell2mat(data); end
If you look further in your code you can see that you have one callback that does
data(end+1,:)={0};
indicating that in that routine you are expecting the uitable to be a cell array. You need to be consistent in how you handle the array. Your lines
res = [A, G ,d, deltax, deltay, cx ,cy, deltaxc, deltayc ,x, y];
set(handles.ut1,'Data',res)
are going to send a numeric array to the uitable even if it started as a numeric table, and if it is a numeric table then appending the {0} to it is going to fail.
You should review all of your code and switch it all to expecting cell array. For example,
set(handles.ut1,'Data', num2cell(res))
Más respuestas (1)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!