polyfit error: Subscripted assignment dimension mismatch.
显示 更早的评论
I am trying to fit a relationship between temperature and salinity values for different depth bins. At the moment polyfit is not working. If I use degree=1, the error I get is:
Subscripted assignment dimension mismatch. Error in temp_sal_plot_K_edits_v2 (line 88) p(i,:)=polyfit(T,S,1); % Find polynomial relationship for this (i) depth bin
Plus I always get a warning message of this:
Warning: Polynomial is badly conditioned. Add points with distinct X values, reduce the degree of the polynomial, or try centering and scaling as described in HELP POLYFIT. > In polyfit at 75 In temp_sal_plot_K_edits_v2 at 40
If I change the degree to 3, polyfit runs, however the fitted polynomial is very inaccurate. Could someone please let me know where I am going wrong? Here is the code:
for i=300:310 % Loop over m steps in depth
T=[];
S=[];
for j=1:nx % Loop over degC steps in tempearure
if vS(i,j) > 0
T=[T qX(i,j)]; % Temperature = temperature value from query points
S=[S vS(i,j)]; % Salinty = salinity value from interpolated grid
end
end
p(i,:)=polyfit(T,S,1); % Find polynomial relationship for this (i) depth bin
fS(i,:)=polyval(p(i,:),qX(i,:)); % Evaluate fS points (Salinity points) for each query point (qX = temperature points) using the derived polynomial expression for this depth bin.
figure;
plot(S,T,'o',qX(i,:),fS(i,:));
xlabel('Salinity, ppt');
ylabel('Temperature, degC');
end
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!