var_1 = ["singnal1","singnal2"];%图一
var_2 = ["singnal3","singnal"];%图二
Modename = uigetfile('*.mat');
load(Modename);
ListName = [Modename(1:end-3),'Y'];
rec_cell = struct2cell(eval(ListName));
list_len = length(eval(ListName));
reshape(rec_cell,[],list_len);
namelist_cell = rec_cell(1,:)';
MatStr = [Modename(1:end-3),'Y(1).Data'];
x_num = length(eval(MatStr))-1;
x = 0:1:x_num;
MatName = [Modename(1:end-3),'Y.Name'];
str = [];str1 = [];str2 = [];
subplot(2,1,1)
for t = 1:length(var_1)
if any(namelist_cell == var_1(t))
str1 = [str1,var_1(t)];
str = Modename(1:end-3) + "Y(" + find(namelist_cell == var_1(t)) + ").Data";
str_plot = str(1);%
plot(eval(str_plot));
title('signal 1');
hold on;
else
disp('mat中不存在 '+ var_1(t));continue
end
end
legend(str1);
subplot(2,1,2)
for t = 1:length(var_2)
if any(namelist_cell == var_2(t))
str2 = [str2,var_2(t)];
str = Modename(1:end-3) + "Y(" + find(namelist_cell == var_2(t)) + ").Data";
str_plot = str(1);
plot(eval(str_plot));
title('signal 2');
hold on;
else
disp('mat中不存在'+ var_2(t));continue
end
end
legend(str2);
plotbrowser('on');
Matlab读取.mat文件画图
最新推荐文章于 2024-09-03 18:54:34 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)