polyfit error: Subscripted assignment dimension mismatch.
Show older comments
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
Accepted Answer
More Answers (0)
Categories
Find more on Logical 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!