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

1 次查看(过去 30 天)
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)

回答(1 个)

dpb
dpb 2018-7-22
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 个评论
dpb
dpb 2018-7-22
编辑:dpb 2018-7-22
"[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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by