How to give variable name to a Mat file?

조회 수: 2 (최근 30일)
Haya Ali
Haya Ali 2023년 3월 18일
댓글: Haya Ali 2023년 3월 18일
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);
Unrecognized function or variable 'X1'.
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;

채택된 답변

the cyclist
the cyclist 2023년 3월 18일
편집: the cyclist 2023년 3월 18일
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
  1. Everywhere in your code that your reference X1, use roi_signal_all instead, because that is the name of the stored variable.
  2. 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.
  댓글 수: 2
Stephen23
Stephen23 2023년 3월 18일
편집: Stephen23 2023년 3월 18일
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.
Haya Ali
Haya Ali 2023년 3월 18일
Thanks a lot!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by