Multiplying structure array with a scaler

16 ビュー (過去 30 日間)
Aldrich Dias
Aldrich Dias 2021 年 3 月 22 日
回答済み: Matt J 2021 年 3 月 22 日
I have Data.mat file that is a 1x365 structure array and i would like to multiply all the values of the 4th column by 2 and store them in to a variable.

採用された回答

Matt J
Matt J 2021 年 3 月 22 日
If you mean you want to multiply all the fields by 2,
s0.a=1;s0.b=2;s0.c=3 %example struct
s0 = struct with fields:
a: 1 b: 2 c: 3
s=structfun(@(f)2*f, s0,'uni',0)
s = struct with fields:
a: 2 b: 4 c: 6

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by