- Everywhere in your code that your reference X1, use roi_signal_all instead, because that is the name of the stored variable.
- Before you run your code, load the MAT file, assign X1 = roi_signal_all, then re-save the MAT file so that it has a variable named X1.
How to give variable name to a Mat file?
3 views (last 30 days)
Show older comments
I have a mat file in which the data is of variable X1 in my program. I loaded the data but it's giving an error. Please help.
load ("X1.mat")
AddnumX1=10;%Num1er of additional data points in each time interval.
NX1=AddnumX1*length(X1); %Length of the reconstructed signal(the continuous signal);
RecX1=zeros([1,NX1]);
RateX1=zeros([1,NX1]);
n_x1=zeros([1,NX1]);
N_X1=zeros([1,length(X1)]);
zeroline_X1=zeros([1,NX1]);
index=0;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:NX1
if mod(i,AddnumX1)==1
index=index+1;
N_X1(index)=i;
end
n_x1(i)=i;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:NX1
RecX1(i)=0;
RateX1(i)=0;
for j=1:length(X1)
RecX1(i)=RecX1(i)+X1(j)*sinc((1/AddnumX1)*(i-AddnumX1*(j-1)));
denom1_1 = (i-AddnumX1*(j-1));
denom1_2 = ((pi/AddnumX1)*(i-AddnumX1*(j-1))^2);
if denom1_1 ~= 0 && denom1_2 ~= 0
RateX1(i) = RateX1(i) + X1(j)*(cos((pi/AddnumX1)*(i-AddnumX1*(j-1)))/denom1_1-sin((pi/AddnumX1)*(i-AddnumX1*(j-1)))/denom1_2);
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
mean_X1=mean(X1);
X1=X1-mean_X1;
mean_RecX1=mean(RecX1);
RecX1=RecX1-mean_RecX1;
0 Comments
Accepted Answer
the cyclist
on 18 Mar 2023
Edited: the cyclist
on 18 Mar 2023
Your code is looking for a variable named X1. The file X1.mat that you load does not contain a variable named X1, it is just named X1. The file just has one variable named roi_signal_all.
Two possible solutions are
2 Comments
Stephen23
on 18 Mar 2023
Edited: Stephen23
on 18 Mar 2023
3. The least-effort solution is to simply assign the content of the MAT file to the desired variable:
S = load("X1.mat");
X1 = S.roi_signal_all;
Tip for the future: always LOAD into an output variable... then you will know what is actually in the MAT file.
More Answers (0)
See Also
Categories
Find more on File Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!