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

2 Ansichten (letzte 30 Tage)
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?

Akzeptierte Antwort

Image Analyst
Image Analyst am 12 Okt. 2021
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';

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by