Clear Filters
Clear Filters

How to concatenate the data in each iteration in the same variable?

4 views (last 30 days)
I am saving the output of the 1st iteration in the images_TRO_pressing , images_TRO_slip, images_TRO_noise, the size of each variabe is 120*120*300
In the other iterations how can I keep adding the data in the same varibales so I end up with size for each of them around 120*120*3600? as well same to the varibale labels_TRO with size 1*900 for one iteration
Note that the third dimension which is the number of matrices varies in each iteration not all iterations give 300.
for i = 1:12
pressing_labels = find(labels_all_Train1(i).labels == 0);
slip_labels = find(labels_all_Train1(i).labels == 1);
noise_labels = find(labels_all_Train1(i).labels == 3);
minimum = min([length(pressing_labels), length(slip_labels), length(noise_labels)]);
random_pressing = randsample(pressing_labels, minimum);
random_slip = randsample(slip_labels, minimum);
random_noise = randsample(noise_labels, minimum);
images_TRO_pressing = HM_all_Train1(i).TRO_heatmap(:, :, random_pressing);
images_TRO_slip = HM_all_Train1(i).TRO_heatmap(:, :, random_slip);
images_TRO_noise = HM_all_Train1(i).TRO_heatmap(:, :, random_noise);
labels_TRO = [labels_all_Train1(i).labels(random_pressing), labels_all_Train1(i).labels(random_slip), labels_all_Train1(i).labels(random_noise)];
end
  16 Comments
M
M on 21 Nov 2023
Edited: M on 21 Nov 2023
@Walter Roberson Thanks a lot, this is worked and thanks for @Dyuman Joshi
but I am wondering why the logical indexing instead of "find" didnt work, any suggestion please?
Walter Roberson
Walter Roberson on 21 Nov 2023
You have not been clear as to what your code is, or what your desired outcomes are.
If you are trying to find N locations each of which correspond to a particular arr value, then you have a few possibilities:
  • do NOT just take arr(LOGICAL MASK) since you already know what the arr values are at those locations because that is how you chose the locations
  • taking a random sub-sampling of a logical mask would get you are random number of elements selected, and would not tell you where they were selected from
  • using find() to locate the elements and taking a random selection from those indices works fine if what you want to know is the locations
  • You could create a vector 1:numel(arr) and index that vector at a logical matrix such as arr==0 ... but you would effectively just have duplicated the work of find() less efficiently

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!