Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I need to use the dimension of a certain array, to use it as a bounder in a loop afterwards. The problem is that I get a list, when write :

Dimensions[ai]= {2}

aiod = Table[ai[[i]] - 1, {i, 1, Dimensions[ai], 1}]

and it does not work. I need to get "2" instead of {2}.

share|improve this question
    
You can use Part, as in {2}[[1]]. –  b.gatessucks Feb 25 '13 at 10:01
1  
Or Length, if the first (outermost) dimension is what you want. –  Verbeia Feb 25 '13 at 10:12
2  
What is your first line Dimensions[ai]={2} intended to do? –  Rojo Feb 25 '13 at 12:14
add comment

1 Answer

up vote 2 down vote accepted

Assuming the first (outermost) dimension is what you want, use Length:

aiod = Table[ai[[i]]-1, {i, Length[ai]}]

Notice I've used a simpler iterator specification.

Anyway, if this is your real problem, then be aware that arithmetic operations in Mathematica are Listable, so you can just write

ai - 1
share|improve this answer
    
This might be useful: mathematica.stackexchange.com/a/7922/8 –  Verbeia Feb 25 '13 at 12:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.