1

stationsフィールドnamecode. _ 例えば:

stations = struct(...
    'name',{'a','b','c','d'},...
    'code',{[0 0],[0 1],[1 0],[1 1]}) 

sessions'(この構造を変更し、新しいステーション名とコードなどを追加します。)フィールドも持つ新しい構造を作成したいのですがnamecode値は 2 つのステーションの組み合わせになりますか?

例えば:

stations = struct(...
    'name',{'ab','ac','ad','bc','bd','cd'},...
    'code',{[0 0 0 1],[0 0 1 0],[0 0 1 1],[0 1 1 0],[0 1 1 1],[1 0 1 1]}).

私は次のようなことを試みています:

for i=1:numberOfStations-1
    for j=i+1:numberOfStations
        strcat(stations(i).name,stations(j).name);
        cat(2,stations(i).code,stations(j).code);
    end 
end

しかし、それらの値をどこに置くべきかわかりません。

4

1 に答える 1

0

あなたstructが持っているのは構造体配列なので、次のように各要素にアクセスします。

stations(1)

ans = 

    name: 'a'
    code: [0 0]

次に、特定の要素とメンバーについて

stations(2).name

ans =

b

構造体に追加する場合は、次の操作を実行できます。

stations(end+1) = struct('name','hi','code',[1 1]);

構造体の新しい配列を現在の構造体にマージする場合:

% current struct array, stations
% new data, new_station_data
for ii=1:length(new_station_data)
    station(end+1) = new_station_data(ii);
end

お役に立てれば!

于 2012-09-19T21:20:11.607 に答える