Importing .csv files and generating surf plots for each

7 views (last 30 days)
Hi All,
Got a hopefully basic Matlab question for everyone here. I'm new to Matlab, so please be patient with what is probably a dumb question.
I have collected lab data in the form of .csv files and plot them in a nice 3D surface plot. These files (there are like 20 of them) do not have any headers or anything of the like, if that helps. They also do not have sequential names (so it's not like "file1.csv" and "file2.csv"). The csv files are large: essentially a matrix of about 3000x3000 numbers.
I can import them one by one into Matlab and create a surface plot of them, but after a while that gets tedious. What I'd like to do is point Matlab at the folder they're in and have it spit out all 20 surface plots in 20 different windows. Any help to this new Matlabber would be greatly appreciated!

Answers (1)

Stephan
Stephan on 14 Mar 2019
Edited: Stephan on 14 Mar 2019
Hi,
have a read here:
This example will enable you to select all needed files and save their file names in a cell array in one single step and then you can process the files by looping through them. For the figure windows use the loop index like:
for k = 1:numel(file)
figure(k)
surf(...)
end
This will alllow you to repeat the process automatically as many times as the number of choosen files is.
Dont forget to use fclose after processing a file. If you search here in the forum for this topic in the accepted answers you will find many examples.
Best regards
Stephan
  3 Comments
Stephan
Stephan on 14 Mar 2019
Edited: Stephan on 14 Mar 2019
The three dots mean that you should fill it with data... You will need to write some more lines of code. This was a hint how to start - not a fully working code. Note that your cell array named file contains all files you wish to plot. In the loop every single file has to be opened, the data it contains has to be imported to Matlab and stored in a usable way for surf and then it has to be closed.
This code has to be written in a way that it works for all your files. If you have don this you are fine. For inporting the data i recommend csvread.
laserdude12
laserdude12 on 14 Mar 2019
First, thanks for the patience, Stephan! It is very much appreciated.
When you say to replace the three dots and fill it with data, how do I go about doing that? I mean, I get you...the cell array named "file" does list the files I'd like to plot, but how would I open each file, plot it, etc.?
Sorry for the dumb questions in advance...

Sign in to comment.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!