Why is matlab unable to perform this script?

Hello,
i have the following script which does a FEM for a room which is imported from GMSH.
Every function works and when i want to run the script, it won't run it. I also tried to clear the workspace but it didnt work as well.
Can anybody help?
It shows in the command window: Unable to perform assignment because the size of
the left side is 1-by-2911 and the size of the
right side is 3347-by-1.
Thank you :)
%Import Raum aus GMSH
m = load_gmsh2('MeshPJ.msh', [1 2]);
P(1,:) = m.POS(:,1); P(2,:) = m.POS(:,2);
T = m.TRIANGLES(:,1:3); GT = m.TRIANGLES(:,4);
L = m.LINES(:,1:2); GL = m.LINES(:,3);
%Aufbau Gitterstruktur
mesh = buildMesh( T,P,[],GT,L,GL );
clear m T P GT L GL
eps= 2*10^-5*ones(1,mesh.NuDoF);
index = (mesh.P(1,:)<=3.2) & (mesh.P(1,:)>=3) & (mesh.P(2,:)<=4) & (mesh.P(2,:)>=1.5);
eps(index) = 8.75*10^-7;
A = assembDiffusion2D (eps, mesh.T, mesh.P);
f =zeros(1,mesh.NuDoF);
b = assembRightSide2D(mesh, f);
%Randwerte setzen
[ A, b ] = applyDirichletBoundaryConditions(A,b, mesh, 20, @(x,y)323.13);
[ A, b ] = applyDirichletBoundaryConditions(A,b, mesh, 21, @(x,y)283.15);
u=A\b;
%Plotten
trisurf(mesh.T,mesh.P(1,:),mesh.P(2,:),u);
xlabel('x [m]'); ylabel('y [m]');zlabel('T [Kelvin]');
colormap('hot'); clim([260 330]);colorbar;

5 Comments

Please post a copy of the complete error message, which tells the readers, inwhich line the problem occurs.
Unable to perform assignment because the size of
the left side is 1-by-2911 and the size of the
right side is 3347-by-1.
Error in PJ2_2 (line 3)
P(1,:) = m.POS(:,1); P(2,:) = m.POS(:,2);
You probably want to at least transpose m.POS before assigning it to P. Then, they are also different lengths. If you are intending to discard the extra values from m.POS, you could do:
P(1,:) = m.POS(:,1:size(P,2))'
Here, the apostrophe character is the MATLAB shorthand for transpose, to turn a column vector into a row vector.
MATLAB automatically transposes vectors if needed when storing them.
Hello,
i tried it and it gave me this error;:
Unrecognized function or variable 'P'.
Error in PJ2_2 (line 4)
P(1,:) = m.POS(:,1:size(P,2))';

Sign in to comment.

Answers (1)

P(1,:) = m.POS(:,1); P(2,:) = m.POS(:,2);
replace that with
P = m.POS(:,[1 2]).';

Categories

Find more on Weather and Atmospheric Science in Help Center and File Exchange

Tags

Asked:

on 10 Jan 2023

Answered:

on 10 Jan 2023

Community Treasure Hunt

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

Start Hunting!