Assigning values from one matrix in a struct to matrix in another struct

1 view (last 30 days)
This is a struct (let's say A_struct) containing results from some calculations in column 1, and in column 2 and 3 are elements that are causing those results, and they are in the same row (results from calculations that use elements in row 1, columns 2 and 3, are situated in row 1 column 1, etc)
So my question is the following: i have to find a minimum value from column 1, and then asign that whole row to another struct (B_struct). Is there a way to do that?
I tried something like this:
B_struct (1,1) = (min(A_struct(:,1)),1);
B_struct (1,2) = (min(A_struct(:,1)),2);
B_struct (1,3) = (min(A_struct(:,1)),3);
this part min(A_struct(:,1)) should specify row from which i want to copy elements. And it doesn't work.

Accepted Answer

the cyclist
the cyclist on 26 Aug 2015
[~,minIdx] = min(A_struct(:,1));
B_struct = A_struct(minIdx,:);

More Answers (0)

Categories

Find more on Structures in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!