How to convert a cell into string?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commento
Stephen23
il 23 Ago 2016
Modificato: Stephen23
il 23 Ago 2016
"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)
Risposte (0)
Vedere anche
Categorie
Scopri di più su Data Type Conversion in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!