How to extract strings from a table?
이전 댓글 표시
Hi all,
I know this is likely a very basic question, but I can't seem to figure it out. I want to extract strings from a table and put them in their own array. My code is here:
IDs=1718; %Define how many IDS there are in the total table; this was determined from the Excel sheet
masterCountSheet = readtable('Tasks_Count_060118 (streamlined).xlsx'); %Create table containing master count sheet data
IDDataArray=zeros(1,IDs)
for i=1:IDs
IDDataArray(i)=masterCountSheet(i,1)
end
However, whenever I reference a specific cell in the table, I get a cell array returned, not a string. Any ideas as to why and how to fix this?
댓글 수: 2
David K.
2019년 10월 2일
If IDDaraArray at the end is a cell array of strings then you should be able to just do
output = string(IDDataArray)
Walter Roberson
2019년 10월 2일
IDDataArray(i)=masterCountSheet{i,1}
채택된 답변
추가 답변 (1개)
Anthony Dave
2020년 11월 27일
편집: Anthony Dave
2020년 11월 27일
@David K and @Walter Roberson's answers enlightened me. You can use the following code in this example.
IDDataArray = string(masterCountSheet{1:IDs,1});
If you just want to read data in all rows, try:
IDDataArray = string(masterCountSheet{:,1});
댓글 수: 1
Simon Schmidt
2021년 4월 29일
Hi! What if only want the first 3 characters (instead of the whole string) of every row?
카테고리
도움말 센터 및 File Exchange에서 Numeric Types에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!