Matrix Dimensions not agreeing

1 回表示 (過去 30 日間)
Joe Bannen
Joe Bannen 2015 年 11 月 13 日
コメント済み: Star Strider 2015 年 11 月 15 日
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