- Notice the orange signs in the column to the right of the editor text pane.
- The variable e3 is underlined
Cant find the number of row for big size of matrix
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a tblBarray matrix of size 13x1
1
3
2
5
4
10
8
11
12
14
15
16
21
and from given list of E3,
Columns 1 through 18
1 1 4 5 1 1 3 1 1 1 2 5 1 1 1 1 3 4
Columns 19 through 36
1 3 5 10 5 4 4 2 3 4 5 8 4 1 1 2 12 16
Columns 37 through 54
1 1 3 3 1 2 10 14 1 1 1 1 1 1 10 8 2 5
Columns 55 through 64
3 15 5 2 1 3 2 21 1 11
I need to search which row thet are belong to that tblBarray
I use this code below
for nE3=1:length (E3)
e31= find(E3(nE3)==tblBarray);
e3=[e3,e31];
end
And get the answer
1 1 5 4 1 1 2 1 1 1 3 4 1 1 1 1 2
Columns 18 through 34
5 1 2 4 6 4 5 5 3 2 5 4 7 5 1 1 3
Columns 35 through 51
9 12 1 1 2 2 1 3 6 10 1 1 1 1 1 1 6
Columns 52 through 64
7 3 4 2 11 4 3 1 2
Then I try for a bigger size of tblBarray unfortunately, it takes a very long time. Can anyone help me how can I solve this? Do i need to change 'find' function? If so, how can I change it?
0 commentaires
Réponse acceptée
per isakson
le 4 Jan 2019
Modifié(e) : per isakson
le 4 Jan 2019
The editor warns you that there is an issue with your code.
Right click the underlined e3
If you have not already preallocated e3, you shall do that.
Compare the speed of your loop with this one
%%
e3 = nan( size(E3) );
for nE3=1:length (E3)
e3(nE3) = find(E3(nE3)==tblBarray);
end
4 commentaires
per isakson
le 4 Jan 2019
Matlab for-loops have a reputation for being slow. However, nowadays they are much faster than they used to be. In your case, I guess the problem is find, especially if tblBarray is large.
Plus de réponses (1)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!