How to prevent array form combining
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Andrew Tubbs
il 23 Gen 2021
Commentato: Andrew Tubbs
il 23 Gen 2021
I have an array in which each value is the variable of another array. My issue is that the arrays inside of the main keep combining into a single array and I need them to remain seperate. This is the problem:
Sub arrays: A1 = [1 2 3] A2 = [4 5 6] A3 = [7 8 9]
Main Array: A = [A1 A2 A3] = [1 2 3 4 5 6 7 8 9]
The issue is, I need to be able to use A1, A2, and A3 as individual array. When I use A(1) to denote the first array A1 = [1 2 3], the main array only gives the number 1 as it has combine all the array and gives the first value in the combination. I know this can be done by using A(1:3), but this will not work since the program contains hundreds of data sets. If anyone can tell me how to maintain the integrity of my array, with an example preferably, it would be much appreciated
0 Commenti
Risposta accettata
Walter Roberson
il 23 Gen 2021
A1 = [1 2 3]; A2 = [4 5 6]; A3 = [7 8 9];
A = {A1, A2, A3}
A{1}
Notice the use of {} for indexing to get to the content of the first "cell".
Note that you will not be able to do mathematics directly on A. For example, you will not be able to do something like
A = A + 1;
Instead you would need something like
A = cellfun(@(C) C+1, A, 'uniform', 0);
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!