简体   繁体   English

马赛克:??? 在赋值 A(I) = B 中,B 和 I 中的元素个数必须相同

[英]MATLAB: ??? In an assignment A(I) = B, the number of elements in B and I must be the same

I'm doing a project modelling the flow of sauce around pasta, using a BEMLIB code for stokes flow called prtcl_3d_ss_visualize.m which is available from "http://dehesa.freeshell.org/BEMLIB/".我正在做一个项目,对意大利面周围的酱汁流动进行建模,使用名为prtcl_3d_ss_visualize.m的斯托克斯流的 BEMLIB 代码,该代码可从“http://dehesa.freeshell.org/BEMLIB/”获得。 Here is the code:这是代码:

%---
file2 = fopen('prtcl_3d_ss_visualize.m')
Npnt   = fscanf(file2,'%f',[1,1])
Nvert  = fscanf(file2,'%f',[1,1])
Nface  = fscanf(file2,'%f',[1,1])
vert   = fscanf(file2,'%f',[3,Nvert]);
wall   = fscanf(file2,'%f',[1,1])
fclose(file2)
%---

for i=1:Nvert
save = vert(2,i);
vert(2,i) = vert(3,i);
vert(3,i) = save;
end

Ic=0; 
for i=1:Nface
for j=1:Npnt
  Ic=Ic+1;
  fac(j,i) = Ic;
end
end

patch('faces',Nfac’,'vertices',vert’,...
      'FaceColor','y',...
      'FaceLighting','phong',...
      'BackFaceLighting','lit')
%light('Position',[1 3 2]);
%light('Position',[-3 -1 3]);
%material dull
%material shiny
%axis vis3d off
axis([-1.5 1.5 -1.5 1.5 -0.5 2.5 ])
%view(45,34)
xlabel('x')
ylabel('z')
zlabel('y')

xw(1)=-1.5; zw(1)=-1.5; yw(1)=wall;
xw(2)= 1.5; zw(2)=-1.5; yw(2)=wall;
xw(3)= 1.5; zw(3)= 1.5; yw(3)=wall;
xw(4)=-1.5; zw(4)= 1.5; yw(4)=wall;
xw(5)=-1.5; zw(5)=-1.5; yw(5)=wall;
patch(xw,zw,yw,yw); 
hold off

I have encountered several errors when inputing the code in matlab, the first of which i solved changing fopen('prtcl_3d') to fopen('partcl_3d_ss_visualize.m') which is the name of he file.我在 matlab 中输入代码时遇到了几个错误,其中第一个我解决了将 fopen('prtcl_3d') 更改为 fopen('partcl_3d_ss_visualize.m') 的问题,这是他的文件名。 The second error I came up against was where I input我遇到的第二个错误是我输入的地方

patch('faces',Nfac’,'vertices',vert’,...
      'FaceColor','y',...
      'FaceLighting','phong',...
      'BackFaceLighting','lit')

Nfac' was orighinally fac'but i got error "??? Undefined function or variable fac" so I changed it to an already defined variable Nfac. Nfac' 最初是 fac' 但我收到错误“??? 未定义的函数或变量 fac”,所以我将其更改为已定义的变量 Nfac。

The problems I am now faced with the last part of the code.我现在面临的问题是代码的最后一部分。 When I enter the first line当我进入第一行

xw(1)=-1.5; zw(1)=-1.5; yw(1)=wall;

I get the error message: "??? In an assignment A(I) = B, the number of elements in B and I must be the same."我收到错误消息:“??? 在赋值 A(I) = B 中,B 和 I 中的元素数必须相同。”

I get this for the rest of the xw,zw,yw inputs too, what am I doing wrong?对于其余的 xw,zw,yw 输入,我也得到了这个,我做错了什么?

I solved changing fopen('prtcl_3d') to fopen('partcl_3d_ss_visualize.m') which is the name of he file.我解决了将 fopen('prtcl_3d') 更改为 fopen('partcl_3d_ss_visualize.m') 的问题,这是他的文件名。

No, you didn't solve it, you broke it.不,你没有解决它,你把它弄坏了。 In the original script, partcl_3d_ss_visualize.m (or the version I found on the internets, at least), we have these lines:在原始脚本partcl_3d_ss_visualize.m (或至少我在互联网上找到的版本)中,我们有以下几行:

file2 = fopen('prtcl_3d.net')
Npnt   = fscanf(file2,'%f',[1,1])
Nvert  = fscanf(file2,'%f',[1,1])
Nface  = fscanf(file2,'%f',[1,1])
vert   = fscanf(file2,'%f',[3,Nvert]);
wall   = fscanf(file2,'%f',[1,1])
fclose(file2)

This opens some sort of data file prtcl_3d.net , and loads in some required values (this file is presumably included somewhere in the code you downloaded).这将打开某种数据文件prtcl_3d.net ,并加载一些必需的值(该文件可能包含在您下载的代码中的某处)。 What you are making it do is make the script load itself and try and find some non-existent floating point numbers at the start of the file.你正在做的是让脚本自己加载并尝试在文件的开头找到一些不存在的浮点数。

Having done this, it is likely that the output of wall is empty.这样做之后,很可能wall的输出是空的。 Therefore yw(1) (1 element) and wall (zero elements) have different sizes and when you try to assign one to the other you get an error.因此yw(1) (1 个元素)和wall (零个元素)具有不同的大小,当您尝试将一个分配给另一个时,您会收到错误。

Important Note: It won't error earlier because it was able to open the file and try to read something - it is your job to check if what was read in is correct.重要提示:它不会更早出错,因为它能够打开文件并尝试读取某些内容 - 您的工作是检查读取的内容是否正确。 In this case, just manually looking at your workspace would have been enough.在这种情况下,只需手动查看您的工作区就足够了。 In other cases, error checking can be done using functions such as isempty , isnumeric , size , and so on depending on what sort of output you're expecting.在其他情况下,可以使用诸如isemptyisnumericsize等函数来完成错误检查,具体取决于您期望的输出类型。


Regarding fac / Nfac , I imagine that this script does not stand alone and you are supposed to run another script or function before this one that creates the correct variables.关于fac / Nfac ,我想这个脚本并不独立,你应该在这个创建正确变量的脚本或函数之前运行另一个脚本或函数。

It says on that website:它在那个网站上说:

BEMLIB is a boundary-element software library of Fortran 77 (compatible with Fortran 90) and Matlab codes accompanying the book by C. Pozrikidis, A Practical Guide to Boundary Element Methods with the software library BEMLIB,'' Champan & Hall/CRC, (2002). BEMLIB 是一个 Fortran 77(与 Fortran 90 兼容)和 Matlab 代码的边界元软件库,由 C. Pozrikidis 编写,使用软件库 BEMLIB 的边界元方法实用指南,'' Champan & Hall/CRC,( 2002)。 Chapters 8-12 of the book contain the BEMLIB User Guide本书的第 8-12 章包含 BEMLIB 用户指南

I suggest you need the BEMLIB User Guide to help you understand what the code does and how to use it, and until you do understand that you shouldn't be making any changes to it.我建议您需要BEMLIB 用户指南来帮助您了解代码的作用以及如何使用它,直到您明白您不应该对其进行任何更改。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在分配A(I)= B中,B和I中的元素数必须相同 - In an assignment A(I) = B, the number of elements in B and I must be the same 赋值A(I)= B时出错,B和I中的元素数必须相同 - error with an assignment A(I) = B, the number of elements in B and I must be the same 在赋值A(I)= B中,B和I中的元素数必须相同 - In an assignment A(I) = B, the number of elements in B and I must be the same 在分配A(I)= B中,B和I中的元素数必须相同 - In assignment A(I) = B, the number of elements in B and I must be the same 请帮助:在分配A(I)= B中,B和I中的元素数必须相同。 的MATLAB - Please Help: In an assignment A(I) = B, the number of elements in B and I must be the same. MATLAB MATLAB:错误:在A(I)= B中,B和I中的元素数必须相同 - MATLAB: error: In A(I) = B, the number of elements in B and I must be the same 如何摆脱这个MATLAB错误? “在赋值A(I)= B中,B和I中的元素数必须相同。” - How do I get rid of this MATLAB error? “In an assignment A(I) = B, the number of elements in B and I must be the same.” 在赋值 A(:) = B 中,A 和 B 中的元素数量必须相同 - In an assignment A(:) = B, the number of elements in A and B must be the same 在赋值 A(:) = B 中,A 和 B 中的元素数量必须相同 - In an assignment A(:) = B, the number of elements in A and B must be the same 逻辑数组 - 在赋值A(I)= B中,B和I中的元素数必须相同 - Logical Arrays - In an assignment A(I) = B, the number of elements in B and I must be the same
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM