Why importing ascii file and doing differentiation on it by GUI MATLAB shows this error 'Undefined operator '<=' for input arguments of type 'cell'.' ?

1 view (last 30 days)
Dears,
I come to my first Matlab code and I have no previous experience with Matlab so I need your help. I wrote the following code in order to load an ascii file of different rows and columns by push_callback in GUI Matlab. Before loading the file I entered value to define the column of interest and I loaded the desired 'tauD'. Afterwards, I need this code to do some differentiations, save the results, and finally to draw the ouput. But, I got the following message
'
' Undefined operator '<=' for input arguments of type 'cell'.
Error in PSD>pushbutton1_Callback (line 128)
I=imp(tauD(1,1)<=imp(:,1)&imp(:,1)<=tauD(end,1),col+1);
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in PSD (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)PSD('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback''
So, could you please help me to fix this errors?
Your efforts and time are deeply appreciated in advance!
tauD_file='myOptions';
col=getappdata(0,'edit1');
load(tauD_file);
tauD=myOptions;
[fnames,fpath]=uigetfile({'*.dat;*.txt','ASCII Files';'*.*','All Files' },'Select data file','MultiSelect','on');
if ~iscell(fnames)
fnames={fnames};
end
for k=fnames
X1 = cell2mat(k)
imp=importdata([fpath,char(X1)]);
I=imp(tauD(1,1)<=imp(:,1)&imp(:,1)<=tauD(end,1),col+1);
[~,fname]=fileparts(char(X1));
dtau=gradient(tauD(:,1));
dtaudD=gradient(tauD(:,1),tauD(:,2));
dtaudlogD=gradient(tauD(:,1),log(tauD(:,2)));
dVdD=I.*dtaudD./dtau;
dVdlogD=I.*dtaudlogD./dtau;
result=[tauD(:,2),dVdD,dVdlogD];
save([fpath,'dVdD(C8)_cyl_0.193_6_',fname,'.dat'],'result','-ascii')
end
set(handles.pushbutton1,'String',filename);
a = get (handles.pushbutton1,'String',dVdlogD(:,1));
b= get (handles.pushbutton1,'String',dVdlogD(:,3));
axes(handles.axes1);
plot(eval(a), eval(b))

Answers (1)

Ahmed Elsherif
Ahmed Elsherif on 30 Nov 2018
@ Walter Robers
Should I change it by cell2mat or what?
  23 Comments
Walter Roberson
Walter Roberson on 13 Dec 2018
I assumed that the files to be loaded are .mat files. In order to use a variable inside a .mat file you need to know the name of the variable -- or else you need to have some way of recognizing that it is the correct variable name by examining the list of variables stored in the file. (For example it is possible to deal reasonably with the case where the .mat file has exactly one variable.)

Sign in to comment.

Categories

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

Tags

Products


Release

R2015b

Community Treasure Hunt

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

Start Hunting!