How to plot .mat file

14 次查看(过去 30 天)
Indrani
Indrani 2023-6-26
回答: Deepak 2023-6-26
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 个评论
Dyuman Joshi
Dyuman Joshi 2023-6-26
How exactly did you obtain this data, in this specific format?
Dyuman Joshi
Dyuman Joshi 2023-6-26
Unfortunately, you misunderstand.
What I meant was, the 730 files, how did you get them?

请先登录,再进行评论。

回答(1 个)

Deepak
Deepak 2023-6-26
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.

类别

Help CenterFile Exchange 中查找有关 Workspace Variables and MAT-Files 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by