How to plot .mat file

15 Ansichten (letzte 30 Tage)
Indrani
Indrani am 26 Jun. 2023
Beantwortet: Deepak am 26 Jun. 2023
Hi!
I have loaded 730 files into matlab. The 730 files have been loaded as cells. Inside each cell is a structure which contains a .mat file. I need to plot the data of the .mat file.
How do I proceed? Is there an easier way to do it?
  2 Kommentare
Dyuman Joshi
Dyuman Joshi am 26 Jun. 2023
How exactly did you obtain this data, in this specific format?
Dyuman Joshi
Dyuman Joshi am 26 Jun. 2023
Unfortunately, you misunderstand.
What I meant was, the 730 files, how did you get them?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Deepak
Deepak am 26 Jun. 2023
To plot the data from the .mat files loaded into MATLAB as cells, you can iterate over each cell, access the structure inside, and then load and plot the data from the .mat file. Here's an example of how you can proceed:
% Assuming your loaded files are stored in a cell array called 'loadedFiles'
numFiles = numel(loadedFiles);
% Preallocate a cell array to store the loaded data
data = cell(numFiles, 1);
% Iterate over each cell and load the .mat file data
for i = 1:numFiles
% Access the structure inside the cell
fileStruct = loadedFiles{i};
% Load the .mat file data
loadedData = load(fileStruct.matFileName); % Replace 'matFileName' with the actual field name
% Store the loaded data in the cell array
data{i} = loadedData;
% Plot the data
% Replace 'yourPlottingFunction' with the function you use to plot the frequency data
yourPlottingFunction(loadedData);
end
In this example, `loadedFiles` is assumed to be a cell array containing the loaded files. You can modify this code to match your specific variable names and structure field names.
The code iterates over each cell, accesses the structure inside using the appropriate field name, loads the .mat file data using the `load` function, stores the loaded data in the `data` cell array, and then plots the data using your chosen plotting function.
By using a loop, you can handle the 730 files efficiently. However, if you find this approach cumbersome, you can consider using the `cellfun` function to apply the loading and plotting operations to each cell in a more concise manner.

Kategorien

Mehr zu Workspace Variables and MAT-Files 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