From: Elod on
Hello

I have a problem with saveing from a list box to a file some data.
My data is 5 numers in a row between them is a space. When i read the content of the list box and try to conver one row into a string i got an error: the variable is not a string.
That is true, matrix[1,1] is alsow a cell.
Pleas help me to convert my data from the list box into a matrix wich has 5 column.

This is my cod for generating the contetnt of the list box and the save function:

function saveintolistbox_Callback(hObject, eventdata, handles)
J1=str2num(get(handles.J1,'String'));
J2=str2num(get(handles.J2,'String'));
J3=str2num(get(handles.J3,'String'));
J4=str2num(get(handles.J4,'String'));
J5=str2num(get(handles.J5,'String'));
lin=[J1 J2 J3 J4 J5];
d=get(handles.commandsline,'String');
peta=cat(1,d,{num2str(lin,'%10.3f')});
set(handles.commandsline,'String',peta);
guidata(hObject, handles);

function savetext_Callback(hObject, eventdata, handles)
filename=uiputfile('.txt');
fID=fopen(filename,'w');
peta=get(handles.commandsline,'String')
speta=size(peta)
for i=1:speta(1);
% format='%f%f%f%f%f';
% p=sscanf(peta(i,1),format)
% fprintf(fID,peta);
% dlmwrite(filename, peta, 'delimiter', '\t','precision', 3);
end
fclose(fID);
From: Steven Lord on

"Elod " <pall.elod(a)gmail.com> wrote in message
news:i16vbt$d54$1(a)fred.mathworks.com...
> Hello
>
> I have a problem with saveing from a list box to a file some data.
> My data is 5 numers in a row between them is a space. When i read the
> content of the list box and try to conver one row into a string i got an
> error: the variable is not a string.
> That is true, matrix[1,1] is alsow a cell. Pleas help me to convert my
> data from the list box into a matrix wich has 5 column.

If you have a cell array whose cells contain strings (char arrays):

M = {'apple', 'banana', 'cherry'}

Then indexing into M using parentheses returns one or more of the cells from
the cell array:

M1 = M(1:2)

while indexing into M using curly braces returns _the contents_ of one or
more of the cells from the cell array.

M2 = M{3}

Note that while M1 is a 1-by-2 cell array, M2 is a 1-by-6 _char_ array.

whos M M1 M2

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com


From: Elod on
Hi!

I resolved the problem somehow on a nother way.
I used an inbuilt matlab function str2mat. I think this is a freaky feature.
In the help is not mantioned this behavior of the function.
this is may code:

function loadtext_Callback(hObject, eventdata, handles)%LOAD txt to listbox
filename=uigetfile('.txt');
% fileID=fopen(filename,'r');
mx=load(filename);
mxs=size(mx); mxs=mxs(1,1);
peta=get(handles.commandsline,'String');
for i=1:mxs
peta=cat(1,peta,{num2str(mx(i,:),'%10.3f')});
end
set(handles.commandsline,'String',peta);%listbox
guidata(hObject, handles);

function savetext_Callback(hObject, eventdata, handles)
filename=uiputfile('.txt');
fID=fopen(filename,'w');
peta=get(handles.commandsline,'String')
speta=size(peta)
mx=[];
for i=1:speta(1);
format='%f%f%f%f%f';
p=sscanf(str2mat(peta(i,1)),format);%here i used str2mat
mx=[mx;p(1) p(2) p(3) p(4) p(5)];
% fprintf(fID,peta);
end
dlmwrite(filename, mx, 'delimiter', '\t','precision', 3);
fclose(fID);