How to convert 1 column from multiple .csv files in workspace for plotting?
Show older comments
Hi everyone,
I have 20 different 601x3 tables in my workspace based on csv file that are all names ZnO1, ZnO2,..., ZnO20. Each csv has x and y data in the first and third column, but the first column is the same for each of them. I used:
wave = ZnO1{:,1};
to create the x axis values for my plot, but now I need to make 20 y-series from the third columns of each ZnO file. I'm hoping to do this with a for loop where I assign the third columns to the respective abs# matrix and then apply a function [log(1/abs)] to each value to find corresponding trans# matrices and ultimately plot the 20 trans# series vs wave. Am I taking the right approach? And how would I change my code?
for k = 1:20
scan{k} = ZnO1{:,3};
end
This is what I have so far, but obviously I don't want it to only use ZnO1.
Thanks in advance!
1 Comment
Ameer Hamza
on 24 Apr 2018
First of all, you are asking for unnecessary complications by naming your variables like this. See https://www.mathworks.com/matlabcentral/answers/304528-tutorial-why-variables-should-not-be-named-dynamically-eval.
It is better to organize your data in matrices or cell arrays. The first suggestion is to combine all these variables into one cell array or MATRIX. Since you data set contain only 10 variables, it might be feasible for you to just do this manually like this
Zn{1} = Zn01;
Zn{2} = Zn02;
% repeat it for 20 times upto Zn20
After that, you can use your loop like this
for k = 1:length{Zn}
scan{k} = Zn{k}{:,3};
end
% do something with scan variable
Answers (0)
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!