How can I use .mat file as new variable?

3 次查看(过去 30 天)
Hello!
I have saved some data from excell to matlab as a .mat file. Now I want to load and use them in matlab. For example, my data are saved in a file called 'DCS_data.mat' which includes 1996*2 data. I want to save the first column in a variable called T and the second column in a variable called heat. But I don't know how to do that. Could you pleae help me with this problem.
Regards,
Faezeh

采纳的回答

Star Strider
Star Strider 2019-7-3
Another option:
S = load('DCS_data.mat');
C = struct2cell(S);
T = C{1}(:,1);
heat = C{1}(:,2);
save('DCS_data(2).mat', 'T', 'heat');
This assumes that the first (perhaps only) matrix in ‘DCS_data.mat’ is the one you want to work with. (It would help to have ‘DCS_data.mat’ to experiment with.) Name your new .mat file whatever you want. I called it ‘DCS_data(2).mat’.

更多回答(2 个)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019-7-3
new_var=load('DCS_data.mat')
  1 个评论
Matt J
Matt J 2019-7-3
编辑:Matt J 2019-7-3
and then
T=new_var.whatever(:,1);
heat=new_var.whatever(:,2);

请先登录,再进行评论。


Faezeh Manesh
Faezeh Manesh 2019-7-4
Thank you very much!

类别

Help CenterFile Exchange 中查找有关 Workspace Variables and MAT-Files 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by