How to create multiple structure variables and assign values to them at one line.

5 vues (au cours des 30 derniers jours)
mohammed tarek
mohammed tarek le 16 Mar 2023
Modifié(e) : Dyuman Joshi le 16 Mar 2023
I want to create a structure type for example 'AC' and assign values to its fields all at one line as follows:
[AC.a, AC.b] = [5, 15]

Réponses (2)

Dyuman Joshi
Dyuman Joshi le 16 Mar 2023
Modifié(e) : Dyuman Joshi le 16 Mar 2023
%Assign any type of data to a field
[AC.a, AC.b, AC.c, AC.d] = deal(5, 15, {'cell'}, '0');
AC
AC = struct with fields:
a: 5 b: 15 c: {'cell'} d: '0'

Voss
Voss le 16 Mar 2023
One way:
[AC.a, AC.b] = deal(5, 15);
AC
AC = struct with fields:
a: 5 b: 15
Another way:
C = {5, 15};
[AC.a, AC.b] = C{:};
AC
AC = struct with fields:
a: 5 b: 15

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by