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

4 views (last 30 days)
nirwana on 13 Apr 2023
Commented: Star Strider on 13 Apr 2023
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?

Star Strider on 13 Apr 2023
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.
.
nirwana on 13 Apr 2023
hi @Star Strider output a have sixe 1x2 and others is 1x1.
Star Strider on 13 Apr 2023
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.