How to print out a cell array inside a cell array
显示 更早的评论
teampick =
1×4 cell array
{1×4 cell} {1×4 cell} {1×4 cell} {1×4 cell}
采纳的回答
How did you manage to get that so deeply nested? Let's see the code that generated the array and work on it...
But, to answer the question, one just keeps on dereferencing layer after layer...
>> v={{{rand(1,1)},{rand(1,1)}}} % WOW! Why would one do this????
v =
1×1 cell array
{1×2 cell}
>> v{1}{1}
ans =
1×1 cell array
{[0.4720]}
>> v{1}{1}{1}
ans =
0.4720
>>
2 个评论
this is why lol
team_pick_order
= [];
% Order of drafting teams
%<SM:RANDGEN>
teamdraft = randperm(num_teams) ;
%assiagn team names to draft order
%<SM:FOR>
for c1 = 1:num_teams
team_number = teamdraft(c1);
team_pick_order = [team_pick_order;teamnames(team_number), team_number];
end
%make array for the draftable player for the teams
%<SM:IF>
if num_teams == 4
teampick = cell(1,4) ;
end
if num_teams == 6
teampick = cell(1,6) ;
end
if num_teams == 8
teampick = cell(1,8) ;
end
%separte the postion to make it easy to draft
[~,~,QBs] = getcsv('QB_Table.csv') ;
[~,~,RBs] = getcsv('RB_table.csv') ;
[~,~,WRs] = getcsv('WR_table.csv') ;
[~,~,TEs] = getcsv('TE_table.csv') ;
[~,~,Ks] = getcsv('K_table.csv') ;
% Eight players on each team
number_of_rounds = 5;
% Repeat so each team gets all of its players
%<SM:FOR>
for round = 1:number_of_rounds
% What row in the draft order?
for row = 1:num_teams
% What team is drafting?
%<SM:RANDUSE>
drafting_team_number = teamdraft(1,row) ;
drafting_team_name = teamnames{teamdraft(row), 1} ;
% picks = teampicks{drafting_team_number}
% Ask the team to pick a player
fprintf('QBs\n')
fprintf('RBs\n')
fprintf('WRs\n')
fprintf('TEs\n')
fprintf('Ks\n')
fprintf('For each team draft one player from each postion.\n')
%<SM:STRING>
String = sprintf('%s please pick your postion you want to draft:', drafting_team_name);
menu = input(String, 's')
%<SM:BUILD>
%<SM:RTOTAL>
%<SM:SWITCH>
switch menu
%<SM:VALID>
case {'QBs','qbs','Qbs','qBs','qbS','QBS','qBS'}
clc;
QBs
%ask for player they want
fprintf('Copy and past player from QB cell array to avoid spelling mistakes.\n')
name = input('Draft your QB: ', 's')
%<SM:FUNCBOTH>
player_loc = lookQB(name,QBs,teampick,menu)
%if player is found place on team and take out of draft
%board
%<SM:CVAL>
%<SM:SEARCH>
if player_loc > 0
teampick{1,teamdraft(row)} = [teampick{1,teamdraft(row)} ; [QBs(player_loc, :),menu]]
QBs(player_loc, :) = [] ;
clc;
end
%<SM:VALID>
case {'RBs','rbs','Rbs','rBs','rbS','RBS','rBS'}
clc;
RBs
%ask for player they want
fprintf('Copy and past player from RB cell array to avoid spelling mistakes.\n')
name = input('Draft your RB: ', 's')
%<SM:SEARCH>
%<SM:CVAL>
player_loc = lookRB(name,RBs,teampick,menu)
%if player is found place on team and take out of draft
%board
if player_loc > 0
teampick{1,teamdraft(row)} = [teampick{1,teamdraft(row)} ;RBs(player_loc, :),menu]
RBs(player_loc, :) = [] ;
clc;
end
%<SM:VALID>
case {'WRs','wrs','Wrs','wRs','wrS','WRS','wRS'}
clc;
WRs
%ask for player they want
fprintf('Copy and past player from WR cell array to avoid spelling mistakes.\n')
name = input('Draft your WR: ', 's')
%<SM:SEARCH>
%<SM:CVAL>
player_loc = lookWR(name,WRs,teampick,menu)
%if player is found place on team and take out of draft
%board
if player_loc > 0
teampick{1,teamdraft(row)} = [teampick{1,teamdraft(row)} ;WRs(player_loc, :),menu]
WRs(player_loc, :) = [] ;
clc;
end
%<SM:VALID>
case {'TEs','tes','tEs','teS','TES','tES','Tes'}
TEs
%ask for player they want
fprintf('Copy and past player from TE cell array to avoid spelling mistakes.\n')
name = input('Draft your TE: ', 's')
%<SM:SEARCH>
%<SM:CVAL>
player_loc = lookTE(name,TEs,teampick,menu)
%if player is found place on team and take out of draft
%board
if player_loc > 0
teampick{1,teamdraft(row)} = [teampick{1,teamdraft(row)} ;TEs(player_loc, :),menu]
TEs(player_loc, :) = [] ;
clc;
end
%<SM:VALID>
case {'Ks', 'ks','KS','K','k'}
clc;
Ks
%ask for player they want
fprintf('Copy and past player from K cell array to avoid spelling mistakes.\n')
name = input('Draft your K: ', 's')
%<SM:SEARCH>
%<SM:CVAL>
player_loc = lookK(name,Ks,teampick,menu)
%if player is found place on team and take out of draft
%board
if player_loc > 0
teampick{1,teamdraft(row)} = [teampick{1,teamdraft(row)} ;Ks(player_loc, :),menu]
Ks(player_loc, :) = [] ;
clc;
end
end
end
%flip draft order so everyone has a fair chance to get a good draft pick
team_pick_order = flipud(team_pick_order);
end
Missing the functions being called, but when you start with cell(), then don't use the curlies "{}" for the array addressing but () to avoid inserting the cell into the cell array.
General rule is to only use cell addressing at the lowest level needed to store disparate data types; the cell array itself is just an array.
Alternatively, instead of cell arrays, consider struct with named fields to hold the disparate content of each team...the positions could be the field names.
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Programming 的更多信息
标签
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
