multi level indexing acess
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I want to get output from below code but Matlab thrown Error:
[1 2 3 4](2)
My desired output is 2.
Note: I need one line answer without using any function.
Thanks
0 Kommentare
Antworten (2)
Walter Roberson
am 14 Jun. 2015
Bearbeitet: Walter Roberson
am 14 Jun. 2015
I would probably use something like:
Index = @(V,K) V(K);
and then Index([1 2 3 4],2)
If I felt especially obscure there would always be
subsref([1 2 3 4], struct('type','()','subs', {[2]})
which is what will happen internally
0 Kommentare
Azzi Abdelmalek
am 14 Jun. 2015
Bearbeitet: Azzi Abdelmalek
am 14 Jun. 2015
v=[1 2 3 4]
v(2)
If you want one line, then just write
v=2
Siehe auch
Kategorien
Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!