I am having 5 .mat files. Each mat file contains 5 parameters. A,B,C,D,E
Now I want to plat a graph which will be considering all mat files.
I want to take C variable which is of a size 200x1 from each mat file, take mean of it for that mat file and then plot it against time.
So at the end I will get a graph with 5 points representing mean of the respective C columns from .mat file.
Can anyone help me to do this?
Here is what I have done till now:
clear all; clc;
myFolder = 'C:\Users\adi\Documents\MATLAB\';
if ~isdir(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
filePattern = fullfile(myFolder, '*.mat');
matFiles = dir(filePattern);
for k = 1:length(matFiles)
end
This is reading the files from my folder. Now Please help me to analyze them!

 採用された回答

Thorsten
Thorsten 2015 年 5 月 26 日
編集済み: Thorsten 2015 年 5 月 26 日

0 投票

In the body of your for loop, write
load(matFiles(k).name)
plot(k, mean(C), '.')
if k == 1, hold on, end

8 件のコメント

adi kul
adi kul 2015 年 5 月 26 日
Thank you for quick reply. But it's giving me
Subscript indices must either be real positive integers or logicals.
error!
adi kul
adi kul 2015 年 5 月 26 日
what will be the reason?
Thorsten
Thorsten 2015 年 5 月 26 日
My fault. Must be matFiles(k) instead of matFiles(i). I corrected the original post.
adi kul
adi kul 2015 年 5 月 26 日
Now it's giving
Error using load
Argument must contain a string.
Thorsten
Thorsten 2015 年 5 月 26 日
Sorry, must be matFiles(k).name, as corrected above.
adi kul
adi kul 2015 年 5 月 26 日
編集済み: adi kul 2015 年 5 月 26 日
I figured it out but now it's giving
Error using load
Unable to read file
'Trial1.mat':
no such file or directory.
The 5 files are Trial1.mat, ....., Trial5.mat
Thorsten
Thorsten 2015 年 5 月 26 日
編集済み: Thorsten 2015 年 5 月 26 日
Does
>> dir
show you Trial1.mat, Trial2.mat etc? If not, you have to move these files to your current directory, or change your current directory to a location where these files are stored.
If yes, you probably have NO read access to the files. You have to add read permission to your files
Unix/Linux/MacOS:
system('chmod u+r Trial*.mat')
Windows:
system("CACLS Trial*.mat /e /p yourlogin:r")
adi kul
adi kul 2015 年 5 月 26 日
Thanks! I misplaced my directories!

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2015 年 5 月 26 日

0 投票

This question is asked daily. See the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F Use the code snippets to loop over files. At the center of the loop, call load(), hold on, and plot().

カテゴリ

ヘルプ センター および File ExchangeFile Operations についてさらに検索

タグ

質問済み:

2015 年 5 月 26 日

編集済み:

2015 年 5 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by