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
0 件のコメント
回答 (1 件)
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 件のコメント
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 Center および File Exchange で Logical についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!