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

조회 수: 9 (최근 30일)
TANDEEP SINGH
TANDEEP SINGH 2019년 5월 19일
편집: Jan 2019년 5월 22일
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
TADA
TADA 2019년 5월 19일
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 2019년 5월 20일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Guillaume
Guillaume 2019년 5월 19일
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
per isakson
per isakson 2019년 5월 20일
편집: per isakson 2019년 5월 20일
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 2019년 5월 20일
GOOD WORK THANK YOU
Can we also try this using textscan function

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by