Matrix Dimensions not agreeing
1 view (last 30 days)
Show older comments
Hi
I am working with the following:
phi = @(ep,r1) exp(-(ep*r1).^2);
ep = 1;
r1=0.1;
S=linspace(0,1);
t=linspace(0,1);
% Randomly Select 10 points from each of S and t.
S_rand = S(sort(randperm(numel(S), 10)));
t_rand = t(sort(randperm(numel(t), 10)));
[S_,t_]=meshgrid(S_rand,t_rand);
X=[S_(:) t_(:)];
D=phi(ep, distm(X,X));
U=bsf(S_,t_,1,1,0.25,0.05);
c=D\U;
I need D to be a 10 x 10 matrix (like U) and not a 100 x 100 matrix as this code is generating. I can't seem to see why this is happening. Any ideas?
Many thanks
Joe
0 Comments
Accepted Answer
Star Strider
on 13 Nov 2015
Two ideas:
First, it’s best to always completely vectorise your functions unless you intend matrix operations:
phi = @(ep,r1) exp(-(ep.*r1).^2);
Second, we don’t have ‘distm’. I would break it out into its own variable for troubleshooting purposes to be certain it is not creating your (100x100) matrix:
X=[S_(:) t_(:)];
Q1 = distm(X,X) % See What ‘distm’ Returns
D=phi(ep, distm(X,X));
6 Comments
Star Strider
on 15 Nov 2015
As always, my pleasure! I appreciate your compliment.
It definitely is! MATLAB Answers is where I learned a lot about MATLAB, both by reading other Answers and by helping to solve problems I would never have encountered otherwise.
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!