関数 'subsindex'の未定義回避

9 views (last 30 days)
Huge Grave
Huge Grave on 13 Jun 2021
Commented: Huge Grave on 13 Jun 2021
% エクセルからテーブルを作製する
Jisho = readtable('dictionary.xlsx','ReadRowNames',true);
%文字を指定し、その行と列を呼び出す
Chushutumoji='apple';
Shoukai = Jisho(Chushutumoji,2)
%%問題の部分
pic_index=table2struct(Shoukai)
A=subsindex(pic_index)
dispic=data_cell{A}
関数 'subsindex' は、クラス 'struct' の値に対して定義
されていません。
エクセルに入力したインデックス((1,1)など入力)を行列deta_cellに入力して出力したいと考えています。
しかし、subindexが未定義というエラーメッセージが発生してしまいます。
このメッセージを回避するにはどのような手段を取るべきなのでしょうか
  2 Comments
Atsushi Ueno
Atsushi Ueno on 13 Jun 2021
この質問の本質は「構造体のpic_indexにおいてsubindexをオーバーライドする方法」でしょうか?
単に「エクセルに入力したインデックス((1,1)など入力)を行列deta_cellに入力して出力」を実現するだけなら、文字列として読み込んだインデックスを数値に変換してdata_cellのindexingに使えば事足ります。
質問の目的が前者でExcel読み込みは単なる事例の場合、下記は回答になっていないのでコメントとさせて頂きます。
% サンプルデータ準備:data_cell(1,1)とdictionary.xlsx(添付ファイル)
data_cell{1,1} = 'test';
% エクセルからテーブルを作製する
Jisho = readtable('dictionary.xlsx','ReadRowNames',true)
Jisho = 5×3 table
Country Index Production ___________ _________ __________ apple {'China' } {'(1,1)'} 71 orange {'America'} {'(2,1)'} 69 grape {'Italia' } {'(3,2)'} 64 peach {'Spain' } {'(4,1)'} 67 banana {'India' } {'(5,3)'} 64
%文字を指定し、その行と列を呼び出す
Chushutumoji='apple';
Shoukai = Jisho(Chushutumoji,2)
Shoukai = table
Index _________ apple {'(1,1)'}
%%問題の部分
% pic_index=table2struct(Shoukai)
% A=subsindex(pic_index)
% 文字列として読み込んでしまうインデックスを数値に変換する
A=sscanf(Shoukai{1,1}{:},'(%d,%d)')
A = 2×1
1 1
% 添え字からインデックス値に変換する
A=sub2ind(size(data_cell),A(1),A(2))
A = 1
dispic=data_cell{A}
dispic = 'test'
Huge Grave
Huge Grave on 13 Jun 2021
ありがとうございます。問題を解決することができました。

Sign in to comment.

Answers (0)

Products


Release

R2017a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!