Why and how can i fix the vert cat error in this code? It works fine with a 3 len string but over that i get a vert cat error
Afficher commentaires plus anciens
function PeaksFlare_Callback(hObject, eventdata, handles)
global s;
set(handles.text12,'String','');
for w=1:length(s)
e=get(handles.text12,'String');
e=[e;num2str(w),'. ',num2str(s(w))];
set(handles.text12,'String',e);
end
set(handles.text11,'visible','on');
set(handles.text12,'visible','on');
Réponse acceptée
Plus de réponses (1)
Geoff
le 24 Fév 2012
What value of s works, and what value of s breaks? Is s a string or an array of numbers?
You need to ensure that length(s) is less than 10 for this code to work. If s is not a string, you need to ensure that num2str(s(w)) is always the same length. You might consider using sprintf and specify padding etc in the format specifier.
eg
e = [e; sprintf('%2d. %c', w, s(w))]; % s is string
e = [e; sprintf('%2d. %-3d', w, s(w))]; % s is up to 3-digit int.
% etc....
Also, I would avoid the constant set and get calls, when you can do it with one set. Who knows - maybe that is what's causing problems:
e = [];
for w=1:length(s)
e = [e;num2str(w),'. ',num2str(s(w))];
end
set(handles.text12,'String',e);
Hope that helps.
Catégories
En savoir plus sur Data Type Conversion dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!