Calling different file names and plotting them

Hello,
I want to do contour plotting from my available 3D co-ordinates. I have a total of 11 .mat files which stores datas of 3D co-ordinates.
I have named the different files name as G1.mat,G2.mat,........,G11.mat. I want to use for loop to contour plot all the 11 datas. Can i be able to increase file name as G1 to G2 and finally G11?
Please correct me if the method is feasible or not.

2 Comments

"I have a total of 11 .mat files which stores datas of 3D co-ordinates."
What are the names of the variable/s in those mat files?
Thankyou I really appreciate it.
I just found out file name is code.mat and G1,G2,......G11,are variables in it. And each varible stores 9*3 matrix data
(X Y Z co-ordinates with 9 datas each, Does this statement agree with matrix data?)
The idea is to contour plot Z cordinates against XY.
I would be very grateful if you help me out in this one as well.

Sign in to comment.

 Accepted Answer

2 Comments

"I just found out file name is code.mat and G1,G2,......G11,are variables in it."
That is unfortunate. Better data design would simply use exactly the same variable name in each mat file, which would make the code simpler and more robust. But assuming that each mat file contains exactly one variable, we can still import this data and process it:
for k = 1:11
F = sprintf('G%d.mat',k);
C = struct2cell(load(F));
M = C{1}; % assumes one variable per file!
... do whatever with matrix M
end
Thanks a lot!
And TBH I thought you wouldn't reply back so I thought to emerge my question as a new thread. I could find no way to mention you on the new thread. I didn't intend to take all the credit. I apologize for that.

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2017a

Community Treasure Hunt

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

Start Hunting!