How to give variable name to a Mat file?

3 visualizaciones (últimos 30 días)
Haya Ali
Haya Ali el 18 de Mzo. de 2023
Comentada: Haya Ali el 18 de Mzo. de 2023
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;

Respuesta aceptada

the cyclist
the cyclist el 18 de Mzo. de 2023
Editada: the cyclist el 18 de Mzo. de 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
  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 comentarios
Stephen23
Stephen23 el 18 de Mzo. de 2023
Editada: Stephen23 el 18 de Mzo. de 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.
Haya Ali
Haya Ali el 18 de Mzo. de 2023
Thanks a lot!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by