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
dpb
2019 年 12 月 4 日
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!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
