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

조회 수: 4 (최근 30일)
nirwana
nirwana 2023년 4월 13일
댓글: Star Strider 2023년 4월 13일
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
nirwana
nirwana 2023년 4월 13일
hi @Star Strider output a have sixe 1x2 and others is 1x1.
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by