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 Center および File ExchangeWhos についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by