Problem when extracting data from string array!

1 次查看(过去 30 天)
Hi! I have this problem when i should read the second line in my array from the xlsx file with sheets and extract the second line in the arry in order to create a new struct with the first two rows from the data I have read from Excel. The problem is not to read the line and get the elements it is that one of the elements that is a string is shown as a 1x24 matrix and the text doesn't show. Anyone out there who know what the problem might be, is it that I have a name that is to long from the beginning in my Excel-file?
for i = 1:n
[~, data_text, data_raw] = xlsread(doc_name, sheets{i}); % Read sheet to Matlab
sheet_struct.(sheets_new{i}) = data_raw
row_one=strcmp(data_text(1,:),'');
row_one=data_text(1,~row_one);
for row_one_idx= 1:length(row_one)
row_two=data_text(2,:)
end
end

回答(1 个)

dpb
dpb 2016-6-8
...
row_one=strcmp(data_text(1,:),'');
row_one=data_text(1,~row_one);
You're searching for an empty character in the string which isn't going to be so, so the result of the assignment of the logical complement if going to end up as
row_one=data_text(1,1);
or the first character of the string only. If that happened to be a leading blank(*), it would appear as if it were nothing.
() I don't recall if *xlsread strips leading blanks from fields or not; I'd presume not although it does skip leading rows/columns that are all empty in the spreadsheet.
I really don't quite follow what you think you're doing here in that test so don't have a specific solution unless it's a typo and the '' was intended as ' ', a blank, maybe???
  2 个评论
studentdavid
studentdavid 2016-6-8
I don't really follow what I am trying to do either... but thank you for your answer, and sorry for my poor english skills. Not my native language.
dpb
dpb 2016-6-8
Well, what are you trying to accomplish? If you can't describe the intent it's not possible to write code to do what you don't know it is you're trying to do. (Sort of a tautology there! :) )
Describe in words what it is your thoughts were in writing those lines or did you copy something from somewhere else and just try to use it not knowing what was being done?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by