Using fit inside a loop

9 visualizzazioni (ultimi 30 giorni)
Jaime De La Mota Sanchis
Jaime De La Mota Sanchis il 14 Set 2021
I have constructed a for loop in which I save a set of XY positions and a measured windspeed field as:
for i=1:50
windX_in_the_node=U(:,:,i);
windX_in_the_node_vector=reshape(windX_in_the_node,size(mediaU,1),1);
matriz_a_enviarX_1_of_50=zeros(size(mediaU,1), 3);
matriz_a_enviarX_1_of_50(:,1:2)=positions;
matriz_a_enviarX_1_of_50(:,3)=windX_in_the_node_vector;
filenameX = sprintf('Xdata_%d_of_50', i);
save(filenameX, 'matriz_a_enviarX_1_of_50')
end
Now, I am looking for a way of also saving a fit of said data using fit. I am using the example code
sf = fit([x, y],z,'poly23')
changed as
sf = fit([positions(:,1), positions(:,2)],windX_in_the_node_vector,'poly23')
however, if I try to put it inside of the for loop simply writing sf(i) =... I get an error. Can I also automate this use of fit or do I need to do this 50 times by hand?
Best regards.
Jaime.
  2 Commenti
源樹 上林
源樹 上林 il 14 Set 2021
> sf(i) =... I get an error.
sf_save{i} = sf;
Jaime De La Mota Sanchis
Jaime De La Mota Sanchis il 14 Set 2021
Thanks this works fine.

Accedi per commentare.

Risposte (1)

darova
darova il 14 Set 2021
Modificato: darova il 14 Set 2021
Try cell
sf{1} = @(x) sin(x);
sf{2} = @(x) cos(x);
x = 0:0.1:10;
plot(x,sf{1}(x),'r')
line(x,sf{2}(x))
  1 Commento
Jaime De La Mota Sanchis
Jaime De La Mota Sanchis il 14 Set 2021
Sorry. I don't understand very well what You are suggesting. However, the comment on my question works fine.

Accedi per commentare.

Categorie

Scopri di più su Interpolation in Help Center e File Exchange

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by