Saving and Loading ECG data (.mat)

Hello. my query is when I load my ECG_Save variable, it does open saved ecg signal along with figure as well. I don't understand why figure open when I load ECG_Save variable ? I only want to see ECG_Save signal when I load it. it seems like figure also saved in ECG_Save data. how can I omit figure when I load data ?
I think I have some problem with this command in the below code : ECG_Save = ECG.Save;
The ECG code is :
while(ishandle(MainFigure_ECG))
ECGCrudeData = fscanf(Serialport, '%s');
ECG.Save(ECG.DataCursor) = str2double(ECGCrudeData);
end
save(['ECG_' datestr(now,30)]);
toc(For1sec)
close all
fclose(Serialport);
fclose(instrfind);
Anothe Script for loading and analyse ECG data: (here figue + ecg signal both shows -> I require only ecg signal here not figure)
load('ECG_20210426T224428.mat');
a=(ECG_Save(1,:));
figure;
plot(a);

 Accepted Answer

When you call save() and do not specify any variable names, then it will save all the variables in the current workspace. Including for example, the result of having called
MainFigure_ECG = figure(41);
You should avoid calling save() with no variable names, or else you should only do the save() from within a function that has a limited number of variables.

8 Comments

Sarfaraz Ahmed
Sarfaraz Ahmed on 26 Apr 2021
Edited: Sarfaraz Ahmed on 26 Apr 2021
Thank you. I tried like this:
ECG_Save = ECG.Save(ECG.DataCursor);
but still when I load data it also open the figue along with ecg signal.
if I avoide ECG_Save command , then I am not able to see my ecg data when I load ECG mat saved file.
can I know please bit more about it ?
Thank you.
The problem is your line
save(['ECG_' datestr(now,30)]);
You did not say which variables to save, so it is going to save everything it can see in the workspace,
Sarfaraz Ahmed
Sarfaraz Ahmed on 26 Apr 2021
Edited: Sarfaraz Ahmed on 26 Apr 2021
Thank you. I want to save ECG.Save signal.
so, can I know please how can I edit this line with parameter ECG.Save ?
save(['ECG_' datestr(now,30)]);
Thank you.
You cannot save just one field out of a struct, but you could
save(['ECG_' datestr(now,30)], 'ECG');
to save just the struct.
Sarfaraz Ahmed
Sarfaraz Ahmed on 26 Apr 2021
Edited: Sarfaraz Ahmed on 26 Apr 2021
Thank you. now its working fine, when I save and load data in this way:
save(['ECG_' datestr(now,30)], 'ECG');
a=(ECG.Save(1,:));
Thank you so much.
"You cannot save just one field out of a struct, but you could"
The save documentation states "'-struct',structName,field1,...,fieldN Store the specified fields of the specified scalar structure as individual variables in the file." Lets try it:
S = struct('A',1,'B',22,'C',333)
S = struct with fields:
A: 1 B: 22 C: 333
save('test.mat','-struct','S','B');
clear
whos -file test.mat
Name Size Bytes Class Attributes B 1x1 8 double
T = load('test.mat')
T = struct with fields:
B: 22
Interesting, I had not encountered that ability before.
Thank you for such assistance.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!