MATLAB Answers

How to multiple read csv and subject it to formula and look then store in matrix mat for plotting.

1 view (last 30 days)
joms
joms on 22 Jul 2018
Edited: dpb on 22 Jul 2018
How to multiple read csv and subject it to formula and look then store in matrix mat for plotting.
G1_01=csvread folder path;
n=find number of files in folder
A=2*G1_01(:,1);
B=2*G1_01(:,2);
C=2*G1_01(:,3);
D=2*G1_01(:,4);
%looping of the csv
for r=1:n
Result = [A;B;C;D]
mat(:,r)= Result;
end
mat=mat
hold on
plot(mat)

Answers (1)

dpb
dpb on 22 Jul 2018
Many Q? here on the same general idea...here's one recent one that should be good outline to follow/modify to specific purposes-- Answer_329697
For some more background the FAQ has more discussion and alternate ways to skin the cat...
There's also a FEX submission Apply-a-function-to-files that has worked pretty well for me for certain instances that hides a lot of the details needed for the file handling.
  2 Comments
dpb
dpb on 22 Jul 2018
"[I] visit your link..."
There actually are three links there, all of which are apropos to the Q?
What, specifically, have you tried out of the FAQ and example using dir to process the files??? I see nothing in the description of the problem that makes such a difficult task.
One issue in your code above is that creating named sequenced variables is a sign of not using Matlab vector operations efficiently.
The snippet
A=2*G1_01(:,1);
B=2*G1_01(:,2);
C=2*G1_01(:,3);
D=2*G1_01(:,4);
...
Result = [A;B;C;D]
is simply
res=2*G1_01(:);
and will result in a 1D vector of all the elements in G1_01 multiplied by 2. Is that really the result wanted--but it's what the semicolon concatenation line as written would do.
Repeating that in a loop is pretty-much "piece o' cake!" -- give it a shot and see where you actually run into a specific problem; folks will be happy to help.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!