Assigning strings from struct variable

4 ビュー (過去 30 日間)
María-José Castilla
María-José Castilla 2021 年 5 月 4 日
Hi everyone! I'm trying to assign string from a structure to a array.
If I try
array=SIGNAL(:).label;
in the command window I get all the strings, but I want to assign it to a variable. If I try with
array=SIGNAL(:).label;
or
array{:}=SIGNAL(:).label;
I just get one of the labels. If I try with...
for i=1:length(SIGNAL)
array(i,:)=SIGNAL(i).label;
end
It works, but I'm trying to do it without a for in order to save time.

採用された回答

Stephen23
Stephen23 2021 年 5 月 4 日
編集済み: Stephen23 2021 年 5 月 4 日
Use a comma-separated list:
Depending on the data class of your data:
array = [SIGNAL.label]; % strings
array = {SIGNAL.label}; % cell array of char vectors
For example:
A(1).C = 'hello'; % char
A(1).S = "cat"; % string
A(2).C = 'world'; % char
A(2).S = "hat"; % string
S = [A.S] % string
S = 1×2 string array
"cat" "hat"
C = {A.C} % cell of char
C = 1×2 cell array
{'hello'} {'world'}
  1 件のコメント
María-José Castilla
María-José Castilla 2021 年 5 月 4 日
Trank you!!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by