How to convert a cell into string?

조회 수: 5 (최근 30일)
Trick Verzosa
Trick Verzosa 2016년 8월 23일
편집: Stephen23 2016년 8월 23일
Hi! I know this is really simple, but after trying all the codes I've learn so far I still encounter error in my m-code. I tried the code that looks like the Index-Match in Excel, and I want the value I got to be displayed in the corresponding GUI. Here is the code:
[material_num, material_text, material_all] = xlsread('MyExcel.xlsx','A1:E50');
refName = get(handles.popupmenu1,'Value');
materialName = char(refName);
materialRow = find(~cellfun('isempty', strfind(material_text,materialName)));
materialref = material_text(materialRow, 2);
set(handles.edit1, 'String', materialref);
The class of the materialref value is a Cell, therefore it cannot be displayed in the Edit box unless converted into a string (as far as I know). I tried sprintf, and even placing {:} after materialref but I always get the error
Too many outputs requested. Most likely cause is missing [] around left hand side that has a comma separated list expansion.
I'm out of options. Any help is appreciated.
  댓글 수: 1
Stephen23
Stephen23 2016년 8월 23일
편집: Stephen23 2016년 8월 23일
"therefore it cannot be displayed in the Edit box unless converted into a string (as far as I know)"
Why just guess what MATLAB does, when you can simply read the documentation? It is easy to locate using any internet search engine, and is free to read for everyone. Once you actually take the time to read the documentation you will learn that an edit uicontrol accepts a cell array of strings, and puts the string from each cell on a new line in the edit box. It also tells you that you need to set Max-Min>1 to enable multiline text in an edit box.
A minimal working example of this is:
>> txt = {'a','b'};
>> edh = uicontrol('Style','edit', 'Max',3, 'String',txt);
>>
In any case if you want help on that error message, please edit your question and show us the entire error message, this means all of the red text. The complete error message contains useful information too!
Please also show the output of these commands:
size(materialref)
class(materialref)
iscellstr(materialref)

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by