How can I match the dimension from two vectors?

1 次查看(过去 30 天)
Hi, I'm coding an app where the user provides data to a UItable and calculus must be made from that. When I enter values like 1,2,3..6 the code works but it launches this "warning: converting X to matrix of double". If I enter up other data it doesn't work because "Arrays have incompatible sizes for this operation." and "Error using curvefit.attention.Error/throw X must be a matrix with one or two columns." I used "format g" but I don't how to set a size for the array.
global tabla
tabla=app.UITable.Data;
h=cell2mat(tabla(:,1));
tP=cell2mat(tabla(:,2));
tT=cell2mat(tabla(:,3));
V=(pi*(dtr/2)^2.*h)/1000; %Volumen recolectado en funcion de la altura del tambor recolector (L)
Q1=V./tT; %Caudal en funcion de los tiempos por acumulado (L/s)
Q2=V./tP; %Caudal en funcion de los tiempos tomados de forma corrida (L/s)
[f1,R]=fit(tT,Q1,'poly1'); %Ajuste polinomico para ecuacion de la recta
Rcuadrado=num2str(R.rsquare); %Regresion lineal de la data obtenida
m1=f1.p1; b1=f1.p2; %donde p1 es pendiente y p2 es punto de corte
fit1=m1.*tT+b1
[f2,R]=fit(tP,Q2,'poly1');
Rcuadrado2=num2str(R.rsquare);
m2=f2.p1; b2=f2.p2;
fit2=m2.*tP+b2
  3 个评论
Giulia Di Giorgio
Giulia Di Giorgio 2023-3-10
of course, I want to try with this data:
on the "h"column: 10.00 , 20.00, 30.00, 40.00
on the "Tiempos P. (s)" column=51.91 54.58 59.58 61.80
on the "Tiempos T. (s)" column=51.91 106.49 166.07 227.87
I'll attatch a screenshot so you can see how the table looks like
Adam Danz
Adam Danz 2023-3-10
Assuming dtr is a 1x1 scalar, h, tP, and tT must be column vectors, otherwise you will get the error you see: X must be a matrix with one or two columns.
I'm curious why you need cell2mat when indexing from a table. It's a bit of a red flag.
Confirm that h, tP, and tT are column vectors and doubles using these lines
assert(isa(h,'double') && isvector(h) && size(h,2)==1, 'h is not a double vector')
assert(isa(tP,'double') && isvector(tP) && size(tP,2)==1, 'tP is not a double vector')
assert(isa(tT,'double') && isvector(tT) && size(tT,2)==1, 'tT is not a double vector')

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Assembly 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by