load and do operations on multiple file in a loop
Show older comments
Hi,
I have my files named 'Us2asp_001.txt', 'Us2asp_002.txt, .......'Us2asp_00n.txt'.
I want to read the files and do similar operations in each of them.
I read about it and got to know that sprintf is a solution. However, the files are saved into a cell array and I am not sure how to do the further calculations.
I am rather new to matlab. Can you please help me with this?
I have attached the code which I want to write in a loop.
Thank you in advance.
Regards
Dipen
data1=readtable('Upasp2_001.txt');
data2=readtable('Upasp2_002.txt');
data3=readtable('Upasp2_003.txt');
%% Changing units
data1{:,2:end}=data1{:,2:end}*-1000;
data2{:,2:end}=data2{:,2:end}*-1000;
data3{:,2:end}=data3{:,2:end}*-1000;
%% Calculation
data1{:,7}=data1{:,3}+data1{:,5};
data1{:,8}=data1{:,4}+data1{:,6};
data1{:,9}=sqrt(data1{:,7}.^2+data1{:,8}.^2);
data1.Properties.VariableNames([7 8 9])={'Px','Py','Ptot'};
data2{:,7}=data2{:,3}+data2{:,5};
data2{:,8}=data2{:,4}+data2{:,6};
data2{:,9}=sqrt(data2{:,7}.^2+data2{:,8}.^2);
data2.Properties.VariableNames([7 8 9])={'Px','Py','Ptot'};
data3{:,7}=data3{:,3}+data3{:,5};
data3{:,8}=data3{:,4}+data3{:,6};
data3{:,9}=sqrt(data3{:,7}.^2+data3{:,8}.^2);
data3.Properties.VariableNames([7 8 9])={'Px','Py','Ptot'};
%% Plotting
figure
plot(data1.uxtop,data1.Ptot,data2.uxtop,data2.Ptot,data3.uxtop,data3.Ptot);
legend('Mesh 1','Mesh2','Mesh3');
title('Load displacement');
xlabel('ux (mm)');
ylabel('Total Load applied (P) kN');
xlim([0,10]);
Accepted Answer
More Answers (1)
madhan ravi
on 11 Jan 2019
0 votes
Lookup cell2mat() , horzcat() , vertcat() and cellfun() to work with cells.
1 Comment
Dipen Bista
on 11 Jan 2019
Categories
Find more on Graphics Performance 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!