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?
댓글 수: 0
답변 (1개)
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
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 Center 및 File Exchange에서 Subplots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!