how to use values from struct in short way ?

2 ビュー (過去 30 日間)
tomer polsky
tomer polsky 2018 年 1 月 2 日
コメント済み: Jan 2018 年 1 月 7 日

hello i have this code :

clear all;

clc;

Values_Of_The_Circuit(1).P_out_sepic=100;

Values_Of_The_Circuit(1).V_desire=18;

Values_Of_The_Circuit(1).R=Values_Of_The_Circuit(1).V_desire*Values_Of_The_Circuit(1).V_desire;

i want that R=V_desire*V_desire is there a way to write it i an short way insted of Values_Of_The_Circuit(1).V_desire ?

回答 (1 件)

Jan
Jan 2018 年 1 月 2 日
編集済み: Jan 2018 年 1 月 2 日
Well, yes: Use a nicer name for the struct:
V(1).P_out_sepic = 100;
V(1).V_desire = 18;
V(1).R = V(1).V_desire ^ 2;
Names of variables should be meaningful and short. If you keep the functions small (magnitude of 100 lines), using shorter names can be more useful (less prone to typos) than including a short story into the name. But add clear and meaningful comments instead.
  2 件のコメント
tomer polsky
tomer polsky 2018 年 1 月 7 日
編集済み: tomer polsky 2018 年 1 月 7 日
thank you very much for your fast answer , any other way ? only to write V_desire for exmpale ?
Jan
Jan 2018 年 1 月 7 日
Writing "V_desire" only would work only, if this is the variable, you want to access. But you want "V(1).V_desire". If the struct V is a scalar, "V.V_desire" would be sufficient, but if V is a array with more than 1 element, "V(1).V_desire" is the only way to access it.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by