How to store multiple variables on Matlab?
1 次查看(过去 30 天)
显示 更早的评论
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
2021-12-9
The best way to keep your variables is to not use clearvars.
What exactly is it you want to do?
回答(1 个)
David Hill
2021-12-9
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Debugging and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!