Extract variable from .mat files

14 Ansichten (letzte 30 Tage)
Haresh Kumar
Haresh Kumar am 9 Nov. 2020
Kommentiert: Stephen23 am 13 Nov. 2020
Hello,
I have mutiple .mat files which I am running in a for loop. I want to extract the data from the specific variable of .mat file. I tried .variable commond, but it didnot work. Could you please suggest me which commond will I use in this case?.
Here is the attached code:
S = dir('*.mat');
LT= [];
for i=1:length(S)
disp(S(i).name)
T = readtable((S(i).name.(A));
Where, A is the vaiable from which I want to extract the data and all .mat files are in tabular format.
Br,
Haresh Kumar
  4 Kommentare
Haresh Kumar
Haresh Kumar am 9 Nov. 2020
I want to read the frrom one specific variable of table (which is in .mat file) and then want to apply the rest of algorithm.
Stephen23
Stephen23 am 9 Nov. 2020
"...all .mat files are in tabular format."
Please upload a sample file by clicking the paperclip button.

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Rik
Rik am 9 Nov. 2020
Bearbeitet: Rik am 9 Nov. 2020
I think I understand what you mean. You will have to use load to load a variable from a mat file:
S = dir('*.mat');
LT= [];
for n=1:length(S)
A=load(fullfile(S(n).folder,S(n).name));
T=A.A;
%remainder of your code here
end
  4 Kommentare
Stephen23
Stephen23 am 9 Nov. 2020
@Rik: probably one of those S variables should be renamed.
Rik
Rik am 9 Nov. 2020
Thanks for the comment. I guess I shouldn't edit code on autopilot (I always load to S). I'll edit my answer.

Melden Sie sich an, um zu kommentieren.


Stephen23
Stephen23 am 9 Nov. 2020
D = 'absolute/relative path to the folder where the files are saved';
S = dir(fullfile(D,'*.mat'));
for k = 1:numel(S)
F = fullfile(D,S(k).name);
T = load(F);
T.A
end
  4 Kommentare
Haresh Kumar
Haresh Kumar am 13 Nov. 2020
Hello,
Thank you for providing the breif information about this commond. I also want to delete the -ve entries from variable (A) before applying the rest of code and for that I am using this commond:
K=T.A;
If K <0
K=[]
else
K= K
But it doesnot work. Could you please guide me how can I solve this problem?.
Br,
Haresh Kumar
Stephen23
Stephen23 am 13 Nov. 2020
The MATLAB way is to use logical indexing:
K = T.A;
K(K<0) = []

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Tables finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by