Issue with 'Conversion to cell from double is not possible' error.

1 view (last 30 days)
Using a GUI to upload data from a user defined location and analyze it. I've come across an issue with the data acquisition. Is there some sort of data type or format conversion that I need to do?
Code:
% --- Executes on button press in readdir.
function readdir_Callback(hObject, eventdata, handles)
% hObject handle to readdir (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Use user defined directory
directory=get(handles.textbox1,'String');
files=dir(directory);
% Build vector of file names in directory
% Files is a struct, 14 different values in field 'name'
% Last 11 values (4-14) are actual data files
% 'files(1).name = '.'
% 'files(2).name = '..'
% 'files(3).name = DetectionCodes.xlsx
% Is used later on and isn't needed for this pushbutton
names = [files(4).name;files(5).name;files(6).name;files(7).name;files(8).name;files(9).name;files(10).name;files(11).name;files(12).name;files(13).name;files(14).name;]
% Loop for uploading data
for i=1:length(names);
s=names(i,:);
s=strcat('\',s);
L=strcat(directory, s)
[num, txt, all] = xlsread(L);
% Excel file must not have first line titles
[m,n]=size(txt);
for j=1:n;
% Deletes space in the string
txt{j}=regexprep(txt{j},'','NaN');
% Assign columns of data to name in column label
txt(j)=num(:,j);
% Create a global variable for all of the data
handles.data(i).txt(j)=num(:,j);
guidata(hObject,handles);
end
guidata(hObject,handles)
end
display('Data reading is complete.')
display(handles);
Error:
??? Conversion to cell from double is not
possible.
Error in ==> GUI_Patchline>readdir_Callback
at 127
txt(j)=num(:,j);
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> GUI_Patchline at 41
gui_mainfcn(gui_State, varargin{:});
Error in ==>
@(hObject,eventdata)GUI_Patchline('readdir_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback

Accepted Answer

Jan
Jan on 28 Dec 2014
Edited: Jan on 28 Dec 2014
It looks strange that you assign the content of the cell txt{j} at first and in the next line the cell txt(j) (round parentheses) is assigned. But the error message means, that txt(j) is a cell and you try to assigne the numerical vector num(:,j). So perhaps you want curly braces in this line also.
By the way: This is nicer:
names = {files(4:14).name};
Prefer fullfile to concatenate folder and file names, because the hard coded appending of backslashes is platform dependent and prone to bugs.
Updating the handles struct in each iteration is a waste of time. Better call guidata once after the loops.

More Answers (1)

Areej Al-Saffar
Areej Al-Saffar on 10 Dec 2016
Hi When i run the LTEDownlinkExample using MATLAB2013 this error appear to me (in LTEDownlinkExample/Spectrum/Spectrum Analyzer.....Conversion to cell from double is not possible.)please help me, thanx
  1 Comment
Image Analyst
Image Analyst on 10 Dec 2016
You posted this as an answer to Zeke. Is this an answer to Zeke's question? Or is it in any way at all related to Zeke's question, except for possibly the same error message? If not, you should start your own question and attach your full m-file and full error message ( ALL the red text) after reading this link.

Sign in to comment.

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!