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

2 次查看(过去 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';

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by