how to input data into an array from csv files in a for loop
Show older comments
I have some csv files broken up and I want to concatenate them all into one big array but I dont want to input them one by one like the commented out code, is there a way to do this? Thank you
Birth1 = 5.6;
Death1 = 1;
for i = 1:17
na = sprintf('Birth2_%g',i);
str = sprintf('Birth2_Cons_muj_%g_bj_%g_Part_%g.csv',Death1,Birth1,i);
na = readmatrix(str);
end
% Birth2_1= readmatrix('Birth2_Cons_muj_1_bj_5.6_Part_1.csv');
% Birth2_2= readmatrix('Birth2_Cons_muj_1_bj_5.6_Part_2.csv');
Birth2 = [Birth2_1 Birth2_2 Birth2_3 Birth2_4 Birth2_5 Birth2_6 Birth2_7 Birth2_8 Birth2_9 Birth2_10 Birth2_11 Birth2_12 Birth2_13 Birth2_14 Birth2_15 Birth2_16 Birth2_17];
When I run the above code I get an error:
Unrecognized function or variable 'Birth2_1'.
Error in concatenating_matrices (line 14)
Birth2 = [Birth2_1 Birth2_2 Birth2_3 Birth2_4 Birth2_5 Birth2_6 Birth2_7 Birth2_8 Birth2_9 Birth2_10 Birth2_11 Birth2_12 Birth2_13 Birth2_14 Birth2_15 Birth2_16 Birth2_17];%
Accepted Answer
More Answers (0)
Categories
Find more on MATLAB 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!