How to store multiple variables on Matlab?

wpp = []; % weight of cataylst change
yapp = []; % mole fraction of species A change
ycpp = []; % mole fraction of species C change
temppp = []; % temperature change
ppp = []; % pressure change
temppp{end+1} = tempp';
wpp{end+1} = wp';
yapp{end+1} = yap';
ycpp{end+1} = ycp';
ppp{end+1} = pp';
clearvars
Sorry can't show the entire code. There is a for loop in between. What is an alternative code of storing the above variables? We want to use a different method. Preferably more efficient but if it is less, it doesnt matter.
Please message here for the enttire code and I will send you through message.

댓글 수: 2

Rik
Rik 2021년 12월 9일
The best way to keep your variables is to not use clearvars.
What exactly is it you want to do?
It's used to exclude temppp ppp ycpp yapp wpp % Stops the variables being cleared each run

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

답변 (1개)

David Hill
David Hill 2021년 12월 9일

1 개 추천

If every line is related and numbers of the same kind (floating point), then storing in a matrix can be more efficient (use indexing).
for k=1:100
m(k,:)=[wpp,yapp,ycpp,temppp,ppp];
end

댓글 수: 1

we tried to put it at the beginning of our code but it says that those variable [wpp,yapp,ycpp,temppp,ppp] are not defined. Is there another way we can store our variables in matrix.

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

카테고리

도움말 센터File Exchange에서 Variables에 대해 자세히 알아보기

질문:

2021년 12월 9일

댓글:

2021년 12월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by