How to read and print text cell by cell in csv file ?

9 vues (au cours des 30 derniers jours)
TANDEEP SINGH
TANDEEP SINGH le 19 Mai 2019
Modifié(e) : Jan le 22 Mai 2019
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 commentaires
TADA
TADA le 19 Mai 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
TANDEEP SINGH
TANDEEP SINGH le 20 Mai 2019
my loop is working and it is reading one by one , just problem is that it is not reading Name coiumn as it is mix of text and numeric.

Connectez-vous pour commenter.

Réponses (1)

Guillaume
Guillaume le 19 Mai 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 commentaires
per isakson
per isakson le 20 Mai 2019
Modifié(e) : per isakson le 20 Mai 2019
I strongly recommend that you first read Access Data in a Table then try
>> 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'
TANDEEP SINGH
TANDEEP SINGH le 20 Mai 2019
GOOD WORK THANK YOU
Can we also try this using textscan function

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by