Output vector from structure

조회 수: 2 (최근 30일)
Ro Sch
Ro Sch 2021년 10월 7일
답변: Image Analyst 2021년 10월 7일
I have saved some data in a structure in the following way:
driver(1).status = 1;
driver(2).status = 3;
driver(3).status = 4;
driver(1).position = 7;
driver(2).position = 4;
driver(3).position = 2;
What I would like to do now is get a vector of the driver.status for example, so receive a vector that says [1,3,4].
When I use the command driver.status, I however get the following output:
ans =
1
ans =
3
ans =
4
I have not found any way so far how to tell Matlab what I want, I am sure there is some function or way of calling the variable but I haven't found that yet. Thanks for your help!

채택된 답변

KSSV
KSSV 2021년 10월 7일
[driver(:).status]

추가 답변 (1개)

Image Analyst
Image Analyst 2021년 10월 7일
Try this:
vec = [driver.status]

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by