Matrix Dimensions not agreeing

1 次查看(过去 30 天)
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

采纳的回答

Star Strider
Star Strider 2015-11-13
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 个评论
Joe Bannen
Joe Bannen 2015-11-14
Thanks, that is absolutely fantastic. This is such a great place to learn more about this awesome computer program!
Cheers
Joe
Star Strider
Star Strider 2015-11-15
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.

请先登录,再进行评论。

更多回答(0 个)

产品

Community Treasure Hunt

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

Start Hunting!

Translated by