Error: indexing must appear last in an index expression.
    3 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Elia
 el 27 de En. de 2014
  
    
    
    
    
    Comentada: Elia
 el 28 de En. de 2014
            i got the following error when i tried to run the code I wrote
 Error using str2func
 Error: ()-indexing must appear last in an index expression.
 Error in Spro>VbR_button_Callback (line 836)
    V=str2func(['@(t)
    ',char(diff(sym(regexprep(char(XFunction_current),'^@\(t\)',''))))]);
 Error in gui_mainfcn (line 96)
        feval(varargin{:});
 Error in Spro (line 42)
    gui_mainfcn(gui_State, varargin{:});
 Error in
 @(hObject,eventdata)Spro('VbR_button_Callback',hObject,eventdata,guidata(hObject))
 Error while evaluating uicontrol Callback
Note: In my code the variable x is equal to the end value of the before last function I enter in .The new function I give or enter in the uitable can be depending on x ,but it should have just one input argument t , so i created x , so when I give x it will be as a number and not variable .
 Tabledata=get(handles.Xtable,'data');
 Positiondata=XTableCurrentdata(:,1);  % matrix of Strings (functions)
 Timedata=XTableCurrentdata(:,2);      %Matrix of Time intervals 
 n=size(Tabledata,1);
 for i=1:n
    Tcurrent = str2num(Timedata{i,1}); %t2 end time of the current function [t1 t2]
    EndTime_current=max(Tcurrent); 
    Xfunc_current= str2func(['@(t,x)' Positiondata{i,1}]);    
    X(1)=0;
    X(i+1)=Xfunc_current(EndTime_current,X(i));
    XFunction_current=@(t) Xfunc_current(t,X(i));
    V=str2func(['@(t) ',char(diff(sym(regexprep(char(XFunction_current),'^@\     
    (t\)',''))))]);
    ...
2 comentarios
  Amit
      
 el 27 de En. de 2014
				I am sorry Sam. My answer was wrong and very wrong. Thats why I deleted it. Your code is right upto the first str2func. The issue is in second str2fun. I donot know much of symbolic toolbox but there will be many here who can help you.
  per isakson
      
      
 el 27 de En. de 2014
				Respuesta aceptada
  Walter Roberson
      
      
 el 27 de En. de 2014
        You would be better off using anonymous functions to capture the value of the variable instead of trying to convert the variable to a specific value in a string and re-converting the string to a function.
You should also consider using func2str() instead of the char() stuff you are using.
As you are using sym() you are using the symbolic toolbox. A better way to do diff() of a function handle F(x), rather than stripping off the anonymous header from char() of the function handle and diff()'ing sym() of that, is to use something like
sym t
diff(F(t),t)
You can then use matlabFunction to convert that symbolic expression back to a function handle.
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!