ind2sub output dimension
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
My question is regarding the output of the ind2sub function. In my code, since the input dimention of ind2sub changes, i should expect the output dimention to change. But a code like this is not working.
B = rand(6,6,6);
A(1:ndims(B)) = ind2sub(size(B),56);
The output of the above code is [56 56 56] while I'm expecting something like [2 4 2].
Any suggestion?
0 Kommentare
Akzeptierte Antwort
Fangjun Jiang
am 11 Dez. 2011
Follow the same clue in the answer to your other question, you can do the following:
B=rand(4,5,6);
Ind=(20:25).';
n=ndims(B);
Sub=cell(1,n);
[Sub{:}]=ind2sub(size(B),Ind)
SubMatrix=cell2mat(Sub)
Sub =
[6x1 double] [6x1 double] [6x1 double]
SubMatrix =
4 5 1
1 1 2
2 1 2
3 1 2
4 1 2
1 2 2
Weitere Antworten (1)
bym
am 10 Dez. 2011
you need multiple assignments for that function.
[r,c,p]=ind2sub(size(B),56)
r =
2
c =
4
p =
2
2 Kommentare
Siehe auch
Kategorien
Mehr zu Directed Graphs finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!