How can I apply data in function?
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
wanna show data in function as val = ~ How can I do this....
採用された回答
Steven Lord
2024 年 7 月 11 日
I'm not sure I understand your question.
Are you asking about how to pass input arguments into a function? If so see this documentation page.
Are you asking how to prompt the user to enter data interactively inside your function? If so look at the input or inputdlg functions, but realize that if you call those functions inside your function then every time your user calls your function they will need to enter the data; you can't call input or inputdlg but "automatically fill in the data".
Are you asking how to ignore input arguments or output arguments in a function definition or a function call respectively? See this documentation page for inputs and this page for outputs.
If those aren't what you were asking, please add some clarification about what exactly you're trying to do.
5 件のコメント
병욱
2024 年 7 月 11 日


There are zeros in that function(SumJtCbnMeanAST). and val(:,:,2) means 2nd week data. only 1st, 5th data are on screen. Wanna have 2nd, 3rd, 4th weeks data too.
Steven Lord
2024 年 7 月 11 日
Can you dynamically create variables with numbered names like x1, x2, x3, etc.? Yes.
Should you do this? The general consensus is no. That Discussions post explains why this is generally discouraged and offers several alternative approaches.
Nowhere in your code do the eval patterns that you're showing generate a dynamic variable name that could end in AST. So it's not clear how you're creating that variable. Fix your code by eliminating the use of eval and show a minimal working example (no more than say a dozen lines of code that we can actually run) that creates that variable and we may be able to offer some guidance.
병욱
2024 年 7 月 11 日
編集済み: Walter Roberson
2024 年 7 月 11 日
for numparameter = 3:5 % Fz, Fy, Ja, Jt, Jp 순
for numjoint = 1:size(joint,1) % Mtp, Ank, Kne, Hip, Cbn 순
eval(sprintf('Trj%s%sA = zeros(401,size(index,1));',char(parameter(numparameter,:)),char(joint(numjoint,:)))); % prelocation
eval(sprintf('Trj%s%sL = zeros(401,fix(size(index,1)/2+0.5));',char(parameter(numparameter,:)),char(joint(numjoint,:))));
eval(sprintf('Trj%s%sR = zeros(401,fix(size(index,1)/2));',char(parameter(numparameter,:)),char(joint(numjoint,:))));
eval(sprintf('Sum%s%sA = zeros(1,size(index,1));',char(parameter(numparameter,:)),char(joint(numjoint,:))));
eval(sprintf('Sum%s%sL = zeros(1,fix(size(index,1)/2+0.5));',char(parameter(numparameter,:)),char(joint(numjoint,:))));
eval(sprintf('Sum%s%sR = zeros(1,fix(size(index,1)/2));',char(parameter(numparameter,:)),char(joint(numjoint,:))));
eval(sprintf('SumAbs%s%sA = zeros(1,size(index,1));',char(parameter(numparameter,:)),char(joint(numjoint,:))));
eval(sprintf('SumAbs%s%sL = zeros(1,fix(size(index,1)/2+0.5));',char(parameter(numparameter,:)),char(joint(numjoint,:))));
eval(sprintf('SumAbs%s%sR = zeros(1,fix(size(index,1)/2));',char(parameter(numparameter,:)),char(joint(numjoint,:))));
for numindex=1:size(index,1) % Trajectory
eval(sprintf('Trj%s%sA(:,numindex) = interp1(transpose(0:100/(length(%s{numindex})-1):100),%s{numindex}(:,numjoint),transpose(0:100/400:100));',...
char(parameter(numparameter,:)),char(joint(numjoint,:)),char(parameter(numparameter,:)),char(parameter(numparameter,:))));
if rem(numindex,2) == 1 % L
eval(sprintf('Trj%s%sL(:,1+fix(numindex/2)) = interp1(transpose(0:100/(length(%s{numindex})-1):100),%s{numindex}(:,numjoint),transpose(0:100/400:100));',...
char(parameter(numparameter,:)),char(joint(numjoint,:)),char(parameter(numparameter,:)),char(parameter(numparameter,:))));
else % R
eval(sprintf('Trj%s%sR(:,fix(numindex/2)) = interp1(transpose(0:100/(length(%s{numindex})-1):100),%s{numindex}(:,numjoint),transpose(0:100/400:100));',...
char(parameter(numparameter,:)),char(joint(numjoint,:)),char(parameter(numparameter,:)),char(parameter(numparameter,:))));
end
end
for numindex=1:size(index,1) % Sum - abs
eval(sprintf('SumAbs%s%sAST(numindex) = sum(abs(%s{numindex}(:,numjoint)))*tsample;',char(parameter(numparameter,:)),char(joint(numjoint,:)),char(parameter(numparameter,:))));
eval(sprintf('SumAbs%s%sAHS(numindex) = sum(abs(%s{numindex}(1:index(numindex,2)-index(numindex,1)+1,numjoint)))*tsample;',char(parameter(numparameter,:)),char(joint(numjoint,:)),char(parameter(numparameter,:))));
eval(sprintf('SumAbs%s%sAPO(numindex) = sum(abs(%s{numindex}(index(numindex,2)-index(numindex,1)+2:end,numjoint)))*tsample;',char(parameter(numparameter,:)),char(joint(numjoint,:)),char(parameter(numparameter,:))));
if rem(numindex,2) == 1 % L
eval(sprintf('SumAbs%s%sLST(1+fix(numindex/2)) = sum(abs(%s{numindex}(:,numjoint)))*tsample;',char(parameter(numparameter,:)),char(joint(numjoint,:)),char(parameter(numparameter,:))));
eval(sprintf('SumAbs%s%sLHS(1+fix(numindex/2)) = sum(abs(%s{numindex}(1:index(numindex,2)-index(numindex,1)+1,numjoint)))*tsample;',char(parameter(numparameter,:)),char(joint(numjoint,:)),char(parameter(numparameter,:))));
eval(sprintf('SumAbs%s%sLPO(1+fix(numindex/2)) = sum(abs(%s{numindex}(index(numindex,2)-index(numindex,1)+2:end,numjoint)))*tsample;',char(parameter(numparameter,:)),char(joint(numjoint,:)),char(parameter(numparameter,:))));
else % R
eval(sprintf('SumAbs%s%sRST(fix(numindex/2)) = sum(abs(%s{numindex}(:,numjoint)))*tsample;',char(parameter(numparameter,:)),char(joint(numjoint,:)),char(parameter(numparameter,:))));
eval(sprintf('SumAbs%s%sRHS(fix(numindex/2)) = sum(abs(%s{numindex}(1:index(numindex,2)-index(numindex,1)+1,numjoint)))*tsample;',char(parameter(numparameter,:)),char(joint(numjoint,:)),char(parameter(numparameter,:))));
eval(sprintf('SumAbs%s%sRPO(fix(numindex/2)) = sum(abs(%s{numindex}(index(numindex,2)-index(numindex,1)+2:end,numjoint)))*tsample;',char(parameter(numparameter,:)),char(joint(numjoint,:)),char(parameter(numparameter,:))));
end
end
for numindex=1:size(index,1) % Sum - with sign, 20231226
eval(sprintf('Sum%s%sAST(numindex) = sum((%s{numindex}(:,numjoint)))*tsample;',char(parameter(numparameter,:)),char(joint(numjoint,:)),char(parameter(numparameter,:))));
eval(sprintf('Sum%s%sAHS(numindex) = sum((%s{numindex}(1:index(numindex,2)-index(numindex,1)+1,numjoint)))*tsample;',char(parameter(numparameter,:)),char(joint(numjoint,:)),char(parameter(numparameter,:))));
eval(sprintf('Sum%s%sAPO(numindex) = sum((%s{numindex}(index(numindex,2)-index(numindex,1)+2:end,numjoint)))*tsample;',char(parameter(numparameter,:)),char(joint(numjoint,:)),char(parameter(numparameter,:))));
if rem(numindex,2) == 1 % L
eval(sprintf('Sum%s%sLST(1+fix(numindex/2)) = sum((%s{numindex}(:,numjoint)))*tsample;',char(parameter(numparameter,:)),char(joint(numjoint,:)),char(parameter(numparameter,:))));
eval(sprintf('Sum%s%sLHS(1+fix(numindex/2)) = sum((%s{numindex}(1:index(numindex,2)-index(numindex,1)+1,numjoint)))*tsample;',char(parameter(numparameter,:)),char(joint(numjoint,:)),char(parameter(numparameter,:))));
eval(sprintf('Sum%s%sLPO(1+fix(numindex/2)) = sum((%s{numindex}(index(numindex,2)-index(numindex,1)+2:end,numjoint)))*tsample;',char(parameter(numparameter,:)),char(joint(numjoint,:)),char(parameter(numparameter,:))));
else % R
eval(sprintf('Sum%s%sRST(fix(numindex/2)) = sum((%s{numindex}(:,numjoint)))*tsample;',char(parameter(numparameter,:)),char(joint(numjoint,:)),char(parameter(numparameter,:))));
eval(sprintf('Sum%s%sRHS(fix(numindex/2)) = sum((%s{numindex}(1:index(numindex,2)-index(numindex,1)+1,numjoint)))*tsample;',char(parameter(numparameter,:)),char(joint(numjoint,:)),char(parameter(numparameter,:))));
eval(sprintf('Sum%s%sRPO(fix(numindex/2)) = sum((%s{numindex}(index(numindex,2)-index(numindex,1)+2:end,numjoint)))*tsample;',char(parameter(numparameter,:)),char(joint(numjoint,:)),char(parameter(numparameter,:))));
end
end
for numleg = 1:3 % 20231225
eval(sprintf('Trj%s%sMean%s(:,numcondition,numsubject,numWeek) = mean(Trj%s%s%s,2);',char(parameter(numparameter,:)),char(joint(numjoint,:)),char(leg(numleg)),char(parameter(numparameter,:)),char(joint(numjoint,:)),char(leg(numleg))))
eval(sprintf('Trj%s%sStd%s(:,numcondition,numsubject,numWeek) = std(Trj%s%s%s,1,2);',char(parameter(numparameter,:)),char(joint(numjoint,:)),char(leg(numleg)),char(parameter(numparameter,:)),char(joint(numjoint,:)),char(leg(numleg))))
for numphase = 1:3
eval(sprintf('Sum%s%sMean%s%s(numsubject,numcondition,numWeek) = mean(Sum%s%s%s%s,2);',char(parameter(numparameter,:)),char(joint(numjoint,:)),char(leg(numleg)),char(phase(numphase,:)),char(parameter(numparameter,:)),char(joint(numjoint,:)),char(leg(numleg)),char(phase(numphase,:))))
eval(sprintf('Sum%s%sStd%s%s(numsubject,numcondition,numWeek) = std(Sum%s%s%s%s,1,2);',char(parameter(numparameter,:)),char(joint(numjoint,:)),char(leg(numleg)),char(phase(numphase,:)),char(parameter(numparameter,:)),char(joint(numjoint,:)),char(leg(numleg)),char(phase(numphase,:))))
eval(sprintf('SumAbs%s%sMean%s%s(numsubject,numcondition,numWeek) = mean(SumAbs%s%s%s%s,2);',char(parameter(numparameter,:)),char(joint(numjoint,:)),char(leg(numleg)),char(phase(numphase,:)),char(parameter(numparameter,:)),char(joint(numjoint,:)),char(leg(numleg)),char(phase(numphase,:))))
eval(sprintf('SumAbs%s%sStd%s%s(numsubject,numcondition,numWeek) = std(SumAbs%s%s%s%s,1,2);',char(parameter(numparameter,:)),char(joint(numjoint,:)),char(leg(numleg)),char(phase(numphase,:)),char(parameter(numparameter,:)),char(joint(numjoint,:)),char(leg(numleg)),char(phase(numphase,:))))
end
end
end
end
you mean this one??
Steven Lord
2024 年 7 月 11 日
Debugging that to figure out what's creating / populating that variable is going to be extremely painful since you're dynamically creating / populating those variables with eval. Use one of the techniques on that page to which I linked to eliminate your usage of eval and it may be easier to debug the code.
병욱
2024 年 7 月 11 日
Thank you for your support, I really appreciate. Have a nice day.
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Structures についてさらに検索
タグ
参考
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)
