How can I create a function that updates a structure whose input is that structure?

1 回表示 (過去 30 日間)
I have the following section of code that I'd like to convert into a function:
count = 1;
for j = 1:length(data_raw{1}.test_date_time)
if data_raw{1}.test_date_time(j) == ...
data_raw{1}.test_date_time(1) + 1
data_raw{2}.test_date_time_single_second_model(count) = ...
data_raw{1}.test_date_time(j);
count = count + 1;
else
end
end
data_raw{2}.test_date_time_single_second_model = ...
data_raw{2}.test_date_time_single_second_model';
The inputs are fields in a the structure data_raw (so, data_raw{1}.test_date_time). The output is the structure data_raw with the new field test_date_time_single_second_model (so, data_raw{2}.test_date_time_single_second_model).
I've looked through previous community responses for similar entries, but I haven't figured out how to create the function I need.
Will someone please help me?

採用された回答

Image Analyst
Image Analyst 2021 年 10 月 12 日
Just have the output be the input:
To call
data_raw = AlterStructure(data_raw );
To define
function data_raw = AlterStructure(data_raw)
count = 1;
for j = 1:length(data_raw{1}.test_date_time)
if data_raw{1}.test_date_time(j) == ...
data_raw{1}.test_date_time(1) + 1
data_raw{2}.test_date_time_single_second_model(count) = ...
data_raw{1}.test_date_time(j);
count = count + 1;
else
end
end
data_raw{2}.test_date_time_single_second_model = ...
data_raw{2}.test_date_time_single_second_model';
  1 件のコメント
Allen Hammack
Allen Hammack 2021 年 10 月 14 日
Thank you for your response!
Everything seems to be working now! Thank you!

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by