我是一个Matlab新手,我正在做结构分析课的作业,我需要输入各种结构构件的关节(节点)的坐标。所以我制作了这段代码。
%% Coordinates for Structure Nodes
Nnodes=input('Enter structure nodes\n');
Coords=zeros(Nnodes,3);
for i = 1:Nnodes
Coords(i,1)= i;
Coords(i,2)= input(['x coordinate of node', num2str(i),' = '],'s');
Coords(i,3)= input(['y coordinate of node', num2str(i),' = '],'s');
end
fprintf('These are the structure coordinates\n');
Coords
当我在x和y中输入范围从0到9的坐标时,此代码有效,但是一旦我输入坐标> = 10,它就会显示此错误
Assignment has more non-singleton rhs dimensions than non-singleton subscripts
答案 0 :(得分:1)
"分配比非单身下标" 具有更多的非单身rhs维度。
问题是你在这里使用字符串。任何大于9或小于0的值都会给出错误。
例如,考虑字符串'18'
。现在'18'
实际上'1'
位于单独的索引处'8'
位于单独的索引索引处,但您尝试将它们保存在一个索引处,即(i,2)
和{{1 }}
解决方案是不要将它们用作字符串。修改后的工作代码是:
(i,3)