2016-09-11 10 views
0

私はMatlabの初心者で、私は構造解析クラスの宿題をしています。様々な構造部材のジョイント(ノード)。だから私はこのコードを作った。入力値と '代入は非シングルトンの添え字よりも非シングルトンrhsの次元が多い' Error

%% 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 

iは0から9の範囲のxとyの座標を入力すると、このコードは、動作iは座標> = 10を入力したら、しかし、それは

Assignment has more non-singleton rhs dimensions than non-singleton subscripts 

答えて

0

このエラーを表示する「代入有します非シングルトンの添え字よりも非シングルトンのrhs次元が多い "
問題は、ここで文字列を使用していることです。 9より大きい値または0より小さい値はエラーを表示します。
たとえば、文字列'18'を考えてみましょう。今度は'18'は別のインデックスでは、別のインデックスでは'8'ですが、1つのインデックス、つまり(i,2)(i,3)に保存しようとしています。

解決策は、文字列として使用しないことです。変更された作業コード:

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),' = ']); 
    Coords(i,3)= input(['y coordinate of node', num2str(i),' = ']); 
end 
fprintf('These are the structure coordinates\n'); 
Coords 
関連する問題