How to read and print text cell by cell in csv file ?
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
firstly See my csv file (test.csv)
Now see code i am using,
InputPython= [csvread('test1.csv',1,0)];
for i = 1:rows(InputPython)
Name = InputPython(i,2)
Length = InputPython(i,3);
width = InputPython(i,4)
D = InputPython(i,5);
Fck = InputPython(i,6);
end_condition = InputPython(i,7)
endfor
output
Name = 0
width = 2
end_condition = 1
Name = 0
width = 2
end_condition = 2
Name = 0
width = 2
end_condition = 3
Name = 0
width = 2
end_condition = 4
Every thing is ok expect Name =0
Name (column 2) have data (S1-101) which is not read by my program because csvread only read numeric.
i tried textscan, importdata, textread they all print full sheet data, but i want result of one by one cell.
Thank you.
i want output like this
Name = S1-101
width = 2
end_condition = 1
Name = S2-102
width = 2
end_condition = 2
5 Commenti
TADA
il 19 Mag 2019
It seems to me that your code doesn't read the values one by one either, so you can import that CSV file in any of the above mentioned methods and use that same loop to iteratively print (or any calculation you're trying to do) row by row and cell by cell
Risposte (1)
Guillaume
il 19 Mag 2019
The brackets around csvread are useless clutter.
rows is not a valid matlab function.
endfor is not a valid matlab statement.
If your question concerns octave, you're in the wrong forum.
csvread can only read numerical data and will return a matrix of numbers. You cannot use csvread to read your file. To read that file properly in matlab, as has been suggested, the simplest way is to use readtable.
InputPython = readtable('test1.csv'); %all done, will correctly use the header to name the table variables.
5 Commenti
per isakson
il 20 Mag 2019
Modificato: per isakson
il 20 Mag 2019
>> T = readtable( 'test1.csv' );
>> stored_in_cell_array = T.Name
stored_in_cell_array =
4×1 cell array
{'S1-101'}
{'S2-102'}
{'S3-103'}
{'S4-104'}
and
>> stored_in_string = convertCharsToStrings( T.Name )
stored_in_string =
4×1 string array
"S1-101"
"S2-102"
"S3-103"
"S4-104"
and
>> NAME3 = T.Name{3}
NAME3 =
'S3-103'
Vedere anche
Categorie
Scopri di più su Text Files in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!