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

2 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Image Analyst
Image Analyst il 12 Ott 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';

Più risposte (0)

Categorie

Scopri di più su MATLAB in Help Center e File Exchange

Prodotti


Release

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by