How to resolve "Conversion to double from cell is not possible."
Show older comments
Can someone point out what I am doing wrong. If I use the internals of the following function in command-line, the code works fine, but when I attempt to execute through the function, I get the error listed above listed for line 12. The offending code is: NewArry(3:LenB+2) = varargin;
function [maxVal, maxInd] = inner_product(varargin)
% varargin contains the accumulated signal returns
K = [2 3 10 2 1];
LenB = length(varargin);
EndL = varargin(1);
EndR = varargin(LenB);
%Pre-allocate New Array
NewArry = zeros(1,LenB + 4);
NewArry(3:LenB+2) = varargin;
NewArry(1) = EndL;
NewArry(2) = EndL;
NewArry(LenB + 3) = EndR;
NewArry(LenB + 4) = EndR;
FinalArry = zeros(1:LenB); %Preallocate array to hold inner product values
for x = 1:LenB
%Take the first group of 5 from the NewArray
Y = NewArry(x:x+4);
%Take The Inner Product of this with the Kernel
IP = Y * K';
%Store this value
FinalArry(1,x) = IP;
end
[maxVal, maxInd] = max(FinalArry);
end
When I assign varargin, and then pass it to the function, [maxVal, maxInd] = inner_product(varargin) it fails.
Thanks
1 Comment
Walter Roberson
on 27 Sep 2018
FinalArry = zeros(1:LenB);
is incorrect. It would try to create a 1 x 2 x 3 x 4 x.... LenB array.
Accepted Answer
More Answers (2)
Babak
on 1 May 2013
use
cell2mat()
David Weuffel
on 27 Sep 2018
Edited: David Weuffel
on 27 Sep 2018
for everybody still searching for answers to this:
it is also possible, that in some scenarios you are trying to convert a char array eg.:
'word'
'2.345'
try using
str2double();
Categories
Find more on Image Arithmetic in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!