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

8 ビュー (過去 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 Center および File ExchangeText Files についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by