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}
채택된 답변
dpb
2019년 12월 3일
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)
