Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Imported Excel strings are not functioning correctly in matlab 2012b

조회 수: 1 (최근 30일)
Michael
Michael 2012년 11월 19일
마감: MATLAB Answer Bot 2021년 8월 20일
I have used xlsread to read in a spreadsheet containing text and numbers. I am trying to use the text to set up a structure system and noticed that the strings read from excel do not resolve the same way strings entered in matlab do. For instance, if I use
structure.('NAME1').('NAME2') = 1;
it correctly generates the structure. However, if I have
[~,names,~] = xlsread(file,sheet,corners);
structure.(names(1,1)).(names(1,2)) = 1;
I get an error saying:
Argument to dynamic structure reference must evaluate to a valid field name.
I've noticed that names(1,1) returns 'NAME1' but the string does not appear in blue in the command window the way it does if I just type 'NAME1'. What is going on here? Is it the difference between an apostrophe and a single quote?
I have similar trouble with cells imported from excel when trying to create vectors with them. Rather than just creating one vector with all the data in it it creates a cell structure with independent cells for the data. What amd I missing about the way matlab reads data from Excel?

답변 (1개)

owr
owr 2012년 11월 19일
Just a guess, but "names" is probably a cell array, so names(1,1) and names(1,2) are 1x1 cell arrays. You need to get access to the character strings within.
Try this instead:
structure.(names{1,1}).(names{1,2}) = 1;
If this is it, spend a little time reading up on the difference of using "(...)" indexing and "{...}" indexing of cell arrays in ML.

이 질문은 마감되었습니다.

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by