Search code examples
matlabmathphysics

Operation .* not supported for operands of type cell (Matlab)


Here is the code that gives the problem:

nVelCurve      =       length( velnum );    % number of assigned velocity curves
pixLocVC       =       vel_imloc(:,1)';     % column index for each assigned velocity curve
nVelPts        =       nan( 1,nVelCurve );  % number of points used from each chosen vel curve 
pix            =       [];                  % row index for TWTT from velmodels, stacked
vels           =       [];                  % velocity for each TWTT from velmodels, stacked

    for i=1:nVelCurve
        
        data      =      sprintf( 'Fit%g', velnum(i) );
        data      =      DataFits.(data); 
        data(:,1) =      data(:,1);  
        dataidx   =      find( [data(:,1).*pps] < Npix ) ; %this line gives the problem
        data      =      data(dataidx,:);  
        pix        =     [ pix; ceil(data(:,1).*pps) ];  
        nVelPts(i) =     length(data); 
        vels       =     [ vels; data(:,2) ]; 
        
    end

For explanation

: data is an n*2 cell array with decimal integers : DataFits is a struct of cell arrays : pps and Npix are decimal integers


Solution

  • Thank You Cris Luego for your effort! I have rewritten the offending line as below:

       dataidx = find( [ cellfun(@(x) x*pps, data(:,1) ) ] < Npix) ;
    

    Kind Regards!