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

8 Ansichten (letzte 30 Tage)
TANDEEP SINGH
TANDEEP SINGH am 19 Mai 2019
Bearbeitet: Jan am 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 Kommentare
TADA
TADA am 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 am 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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Guillaume
Guillaume am 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 Kommentare
per isakson
per isakson am 20 Mai 2019
Bearbeitet: per isakson am 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 am 20 Mai 2019
GOOD WORK THANK YOU
Can we also try this using textscan function

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by