Subscripted assignment dimension mismatch error

I'm having this error and unfortunately I can't seem to see what's wrong in it. Here are the dimension of the variables:
ki=150, a=0, b=2, hx=0.1818, c=0, d=5, hy=0.3125, pi=150x1 double
Thank you in advance!
figure(1)
U(1:ki,1:ki)=pi;
[X,Y]=meshgrid(a:hx:b,c:hy:d);
surf(X,Y,U');

 採用された回答

Dave B
Dave B 2021 年 10 月 22 日

0 投票

When you write:
U(1:ki,1:ki)=pi;
You're trying to put a 150x1 into a 150x150...Maybe what you intended was:
U(1:ki,1:ki)=repmat(pi,1,150);
It's a little unclear what you're after, but if you want to assign to a 150x150 you should probably give it a 150x150

4 件のコメント

Alexandra Roxana
Alexandra Roxana 2021 年 10 月 22 日
I want to use surf for a figure. I used the finite element method and I have 2 solutions u1, u2 (150x1 double variables). From u1 I calculate the pressure, noted as pi (which is 150x1 double as well).
For the graph, I want it to be within the domain, a rectangle with a=0, b=2, c=0, d=5, hx is the time step for the x-axis (with a,b), hy is the time step for the y-axis. The graph is for pi.
Unfortunately I have a new error now: Error using surf (line 82)
Data dimensions must agree.
Alexandra Roxana
Alexandra Roxana 2021 年 10 月 22 日
If it is of any help, I can post the whole code.
Dave B
Dave B 2021 年 10 月 22 日
You said you calculate pressure from u1, so I'm not sure what the surface is as pressure doesn't depend on u2...
U = repmat(pi,1,ki);
[X,Y] = meshgrid(linspace(a,b,ki),linspace(c,d,ki));
surf(X,Y,U');
For example:
u1=linspace(0,2*pi,100)';
u2=linspace(0,1,100)';
zi=sin(u1);
[u1i,u2i]=meshgrid(u1,u2);
surf(u1i,u2i,repmat(zi,1,numel(u1)))
If you want to form a matrix U out of various combinations of u1 and u2, I think you'll need interpolation (e.g. interp2, scatteredinterpolant, griddedinterpolant)
Alexandra Roxana
Alexandra Roxana 2021 年 10 月 23 日
It's the first time I'm computing something like that, but at least I can see a graph. Thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGraphics Performance についてさらに検索

製品

リリース

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by