Effacer les filtres
Effacer les filtres

How to convert a cell into string?

2 vues (au cours des 30 derniers jours)
Trick Verzosa
Trick Verzosa le 23 Août 2016
Modifié(e) : Stephen23 le 23 Août 2016
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 commentaire
Stephen23
Stephen23 le 23 Août 2016
Modifié(e) : Stephen23 le 23 Août 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)

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Data Type Conversion dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by