Windows 如何从matlab中已有的结构中生成新的结构?
我有带字段名称和代码的结构站。 例如:Windows 如何从matlab中已有的结构中生成新的结构?,windows,matlab,Windows,Matlab,我有带字段名称和代码的结构站。 例如: stations = struct(... 'name',{'a','b','c','d'},... 'code',{[0 0],[0 1],[1 0],[1 1]}) 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
stations = struct(...
'name',{'a','b','c','d'},...
'code',{[0 0],[0 1],[1 0],[1 1]})
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]}).
我将改变这种结构,添加新的电台名称和代码等。
我想做一个新的结构会话,它也有字段名称和代码,但值是两个站的组合
例如:
stations = struct(...
'name',{'a','b','c','d'},...
'code',{[0 0],[0 1],[1 0],[1 1]})
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
但是我不知道把这些值放在哪里。您拥有的结构是一个结构数组,因此您可以访问每个元素,如:
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
希望这有帮助 为什么这个标签是Android?为什么它没有被标记为matlab?