Info
此问题已关闭。 请重新打开它进行编辑或回答。
i want to made struct <1*11> of s_input for 10 number of nodes(NB_NODES) without pre defining NB_NODES outside of the struct because i have to use this NB_NODES in other functions by giving its reference..
4 次查看(过去 30 天)
显示 更早的评论
s_input = struct('V_POSITION_X_INTERVAL',[0 30],...%(m)
'V_POSITION_Y_INTERVAL',[0 30],...%(m)
'V_SPEED_INTERVAL',[0.2 2.2],...%(m/s)
'V_PAUSE_INTERVAL',[0 1],...%pause time (s)
'V_WALK_INTERVAL',[2.00 6.00],...%walk time (s)
'V_DIRECTION_INTERVAL',[-180 180],...%(degrees)
'SIMULATION_TIME',500,...%(s)
'NB_NODES',10,.....
'energy',E);
plz help me that how can i made s_input struct of 1*11 for 10 NB_NODES,but i does not want to define NB_NODES outside the struct...........
0 个评论
回答(1 个)
Walter Roberson
2016-11-5
I am not sure what you are trying to do, but perhaps
s_input = struct('V_POSITION_X_INTERVAL',[0 30],...%(m)
'V_POSITION_Y_INTERVAL',[0 30],...%(m)
'V_SPEED_INTERVAL',[0.2 2.2],...%(m/s)
'V_PAUSE_INTERVAL',[0 1],...%pause time (s)
'V_WALK_INTERVAL',[2.00 6.00],...%walk time (s)
'V_DIRECTION_INTERVAL',[-180 180],...%(degrees)
'SIMULATION_TIME',500,...%(s)
'NB_NODES',repmat({10},1,11),.....
'energy',E);
?
Or perhaps
s_input = struct('V_POSITION_X_INTERVAL',[0 30],...%(m)
'V_POSITION_Y_INTERVAL',[0 30],...%(m)
'V_SPEED_INTERVAL',[0.2 2.2],...%(m/s)
'V_PAUSE_INTERVAL',[0 1],...%pause time (s)
'V_WALK_INTERVAL',[2.00 6.00],...%walk time (s)
'V_DIRECTION_INTERVAL',[-180 180],...%(degrees)
'SIMULATION_TIME',500,...%(s)
'NB_NODES',10,.....
'energy',E);
s_input = repmat(s_input, 1, s_input.NB_NODES+1);
6 个评论
Walter Roberson
2016-11-9
Why should it do any differently? You are sending in identical structure members.
In any case if you want the generation routine to work on structure arrays then you need program it to do so. That might just involve one more outer level of looping. It depends on whether the members interact. Why not just loop calling the generation routine? You can do that with arrayfun
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!