# Add 3 rows to then end of an existing array

7 vues (au cours des 30 derniers jours)
Zoey le 9 Fév 2024
I have the data
data = [159 185 170 169 163 180 177 168 175 ; 59 88 75 77 68 90 93 76 70];
weight = data(2,:);
height = data(1,:);
The Top row is height in cm and the bottom row is Weight in kg
I want to add 2 more columns, that come from existing data which is a calculated Minimum, maximum and average for the height and weight.
Here are those variables:
Min = [MinH; MinW; MinB]
Max = [MaxH; MaxW; MaxB]
Avg = [AvgH; AvgW; AvgB]
These return columns of 2 row by 1 column numbers that I want to add to the end of my already existing array
##### 1 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
Stephen23 le 9 Fév 2024
Modifié(e) : Stephen23 le 10 Fév 2024
"Add 3 rows to then end of an existing array"
"I want to add 2 more columns"
So which do you want: to add 3 rows or 2 columns... or both?
Currently your DATA array has size
data = [159 185 170 169 163 180 177 168 175 ; 59 88 75 77 68 90 93 76 70];
size(data)
ans = 1x2
2 9
Adding 3 rows would make it 5x9... but what should those extra 27 values be?
Adding 2 columns would make it 2x11... which requires 4 extra values, but you have given us three new vectors(?) to append. Even if each of those vectors has size 2x1 as you claim (which I doubt) then that would give a total of 6 extra values... which would mean 3 extra columns (i.e. size 2x12), not 2 extra columns as you request.
Adding both would give a 5x11 array...
You write that "These return columns of 2 row by 1 column" which must mean one (or more) of the inputs to each of those three concatenations must be empty. That seems... unlikely. I would assume that each of e.g. MinH, MinW, & MinB would be scalar and thus would concatenate into 3x1 vectors, not 2x1 vectors as you described.
Or do you want to concatenat them onto the WEIGHT and HEIGHT vectors? Given the mix of data in your Min & Max & Avg vectors that also seems unlikely.
It is unclear what you really have and what you really want to get.

Connectez-vous pour commenter.

### Réponses (1)

Image Analyst le 10 Fév 2024
To enlarge an array with more rows and/or columns, you can set the lower right index to zero. This will pad the matrix with zeros.
m = rand(2, 3) % Initial matrix is 2 rows by 3 columns
m = 2x3
0.0311 0.7931 0.4601 0.7510 0.5525 0.3834
mCopy = m;
% Now make it 2 rows by 5 columns
m(2, 5) = 0
m = 2x5
0.0311 0.7931 0.4601 0 0 0.7510 0.5525 0.3834 0 0
m = mCopy; % Go back to original matrix.
% Now make it 3 rows by 3 columns
m(3, 3) = 0
m = 3x3
0.0311 0.7931 0.4601 0.7510 0.5525 0.3834 0 0 0
m = mCopy; % Go back to original matrix.
% Now make it 3 rows by 7 columns
m(3, 7) = 0
m = 3x7
0.0311 0.7931 0.4601 0 0 0 0 0.7510 0.5525 0.3834 0 0 0 0 0 0 0 0 0 0 0
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Logical dans Help Center et File Exchange

R2023a

### Community Treasure Hunt

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

Start Hunting!

Translated by