How to name every row of 100*2500 matrix?
Mostra commenti meno recenti
currently i am working with a matrix. The dimension of the matrix is 100*2500. I need to assign each row the matrix to a new variable. How i can do this?
6 Commenti
per isakson
il 1 Nov 2017
Modificato: per isakson
il 1 Nov 2017
- Why do you need that?
- See TUTORIAL: Why Variables Should Not Be Named Dynamically (eval)
David Goodmanson
il 1 Nov 2017
Modificato: David Goodmanson
il 4 Nov 2017
Hi Md,
The idea of a truckload of variable names, usually to label the individual rows or columns of a matrix, comes up frequently on this website. And every time someone weighs in to say that that style of coding is not a good idea. It's usually awkward, cluttered, susceptible to mistakes and, once created, resistant to improvements using the kind of array-oriented coding that Matlab is really all about. There are many advantages to using, e.g. A(32,:) for a row variable instead of making up a hard-coded variable like A32 in its place.
Md Monirul Islam
il 1 Nov 2017
per isakson
il 1 Nov 2017
Modificato: per isakson
il 1 Nov 2017
Ok, but
- Have you considered to use a structure with 100 fields?
- Those hundred names from where do they come? Do you have a cell array of good names? Do you want to create the names according to some rule?
- Why doesn't [cA,cD] = dwt( M(rr,:), 'wname' ) where rr is row number work?
Md Monirul Islam
il 1 Nov 2017
Modificato: per isakson
il 1 Nov 2017
Les Beckham
il 1 Nov 2017
But Matlab is designed to allow you to operate on matrices and (more specifically, in this case) subsets of matrices using indexing. That is what per has suggested and, I think, you should try. You don't need to give a separate name like row1 to data(1,:), etc. -- just apply your operation to data(1,:), probably using a loop where the 1 is replaced by the loop index. Then you don't have to code a hundred lines to process row1 through row100.
Please note especially the last bullet in per's last comment.
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Logical in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!