How to save result after run function for different input in matlab

4 次查看(过去 30 天)
I use a function with different input, but the input has no
temp=[26.67 93.33 148.89 315.56];
visc=[1.35 0.085 0.012 0.00075];
subplot(2,2,1)
[a,r2,stee] = linregr(temp,visc)
subplot(2,2,2)
[a,r2,stee] = linregr(temp,log(visc))
subplot(2,2,3)
[a,r2,stee] = linregr(log(temp),log(visc))
subplot(2,2,4)
[a,r2,stee] = linregr(1./temp,1./visc)
if i run it,last value of a, r2 and stee is come from last input. I would like to save every output function and put it in certain coulumn but i don't want to use different variable name (exp : a-1,r2-1, stee-1). Do you have any idea how to save it?

回答(1 个)

Star Strider
Star Strider 2023-4-13
I would just subscript it —
subplot(2,2,1)
[a{1},r2{1},stee{1}] = linregr(temp,visc)
subplot(2,2,2)
[a{2},r2{2},stee{2}] = linregr(temp,log(visc))
subplot(2,2,3)
[a{3},r2{3},stee{3}] = linregr(log(temp),log(visc))
subplot(2,2,4)
[a{4},r2{4},stee{4}] = linregr(1./temp,1./visc)
IU use cell array indexing here because I do not know the sizes of the variables being returned. Regular numeric array indexing will work if you know the sizes and that they do not change between the function calls.
.
  2 个评论
Star Strider
Star Strider 2023-4-13
The cell approach will still work.
Using array indexing, the (1x2) result (whatever it is) could be indexed by (k,:) and the scalar results as simply (k) where ‘k’ is any integer greater than zero. Increment ‘k’ for each result.

请先登录,再进行评论。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by