MATLAB Answers


Get a matrix by interaction

Asked by Ricardo Gutierrez on 21 Aug 2019
Latest activity Commented on by Ricardo Gutierrez on 22 Aug 2019
Hello good day.
A synthesis of the code or pseudocode is shown.
clc; clear; close all; short format
Ccl = 21; % Number of lines
gen = 1; % Number of times the code is repeated in each generation (gen)
for wl = 1: gen
for kk = 1: Ccl
Obtaining the values of:
dx1, dy1, dx2, dy2, dx3, dy3, SLL
BCG = horzcat (dx1, dy1, dx2, dy2, dx3, dy3, SLL);
[minimum, row] = min (BCG (:, end));
generate = BCG (row, 1: end-1)
m (wl) = minimum
In the result I get a matrix ("BCG") of size 21 X 7 With the variable "gen = 1"
Giving the value of 3 to the variable "gen" gives me a matrix ("BCG") of 21 X 21
that is to say it shows me a matrix with 3 times each of the variables
What do I have to do to obtain a matrix ("BCG") of 21 X 7 in each generation (gen) and that in each generation (gen) the corresponding matrix ("BCG") is saved?


Sign in to comment.



1 Answer

Answer by James Tursa
on 21 Aug 2019
 Accepted Answer

Maybe use cell arrays. E.g.,
BCG{gen} = horzcat (dx1, dy1, dx2, dy2, dx3, dy3, SLL);
Then everywhere downstream in your code, use BCG{gen} to get at the underlying matrix. E.g.,
[minimum, row] = min (BCG{gen}(:, end));
generate = BCG{gen}(row, 1: end-1)

  1 Comment

Excelent !!!
Thank you

Sign in to comment.