필터 지우기
필터 지우기

How to create many matrixes in one structure?

조회 수: 1 (최근 30일)
Bartosz Bagrowski
Bartosz Bagrowski 2022년 5월 16일
답변: Image Analyst 2022년 5월 16일
Hi guys,
I faced such a problem. I have two functions:
1) function sol = CreateRandModel(model)
2) function qnew = CreateNeighbor(q,model)
In the first function, as an output I get an array (fburn_rand) 1x25 with values. In the second function, I would like create a structure Q (?) which will contain for example 100 of such an arrays, I just don't want the values to be mixed inside so it would look like this: Q=[fburn_rand1 fburn_rand2 ... fburn_rand100] and in the same function I would like to switch later two randomly picked whole arrays inside Q, for example Q=[fburn_rand4 fburn_rand2 fburn_rand3 fburn_rand1 ... fburn_rand100] if 1 and 4 elements would be randomly picked. Is the structure a good idea? Maybe it can be done differently?
I would be thankful for every answer.

답변 (1개)

Image Analyst
Image Analyst 2022년 5월 16일
You need an array of structures, or "structure array":
for k = 1 : 100
Q(k).fburn_rand = CreateRandModel(model);
end
To pick two random structures and swap them, I think this will work
randomIndexes = randperm(length(Q), 2);
[Q(randomIndexes(2)), Q(randomIndexes(1))] = deal(Q(randomIndexes(1)), Q(randomIndexes(2)))

카테고리

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

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by