# MATLAB vector value location ID

• MATLAB
• DoubleHubble
Thanks again for your help!In summary, you can use the interp1 command in MATLAB to generate an interpolation between two points in time.

#### DoubleHubble

HELP! MATLAB vector value location ID?

In MATLAB, say I have two vectors of the same length -- because one is dependent on the other. In my case the independent vector is t, time, and the dependent is p, pressure.

t = 0:500 with an arbitrary time step (finer than 0.2 seconds).

I would like to know the easiest way to extract the value of p at t = 300.2. Any ideas?

Last edited:

DoubleHubble said:
In MATLAB, say I have two vectors of the same length -- because one is dependent on the other. In my case the independent vector is t, time, and the dependent is p, pressure.

t = 0:500 with an arbitrary time step (finer than 0.2 seconds).

I would like to know the easiest way to extract the value of p at t = 300.2. Any ideas?

Well, the problem can be restated as follows: you know the value of p at 501 evenly spaced points in time and you want to use this to infer a value for p at some intermediate point. You solve problems like this using an interpolation of some type. Matlab has a range of commands with which you can generate interpolations; since your problem is one-dimensional you'll probably want to use the interp1 command. Type the following and see where Matlab leads you.

Code:
doc interp1

I understand your response, shoehorn, though it is not exactly what I am looking for. Basically I'm looking for the simplest way to arrive at the result of:

p = 1.1:0.1:10;
t = 16:1.5:150;

for i = 1:length(t)
if t(i) == 53.5
ival = i;
break
end
end

t(ival)
p(ival)

p = 1.1:0.1:10;
t = 16:1.5:150;
p(t==53.5)

AWESOME! Thanks.

What do you mean by corresponds to? Since 5 is the 5th element of t, putting p(t==5, 2) gives 9 since that is the 5th element of the 2nd column. What would you like the output to be?

Yea, I figured it out (which is why I removed my post). The example I had given above was different than what I was running on my machine. I discovered my "t" vector, for the simulation I was running on my computer, had machine epsilon in it. If I did p(t>5-eps & t<5+eps,2) it worked. Sorry for the confusion.

## 1. What is a MATLAB vector value location ID?

A MATLAB vector value location ID is a unique identifier assigned to each element in a vector, which represents its position within the vector. This ID is used to easily access and manipulate specific elements within the vector.

## 2. How do I find the location ID of a specific value in a vector in MATLAB?

To find the location ID of a specific value in a vector, you can use the "find" function in MATLAB. This function will return the indices of all elements in the vector that match the specified value. The first index in the returned list will be the location ID of the first matching value.

## 3. Can I change the location ID of an element in a MATLAB vector?

No, the location ID of an element in a MATLAB vector is determined by its position within the vector and cannot be changed. However, you can change the value of an element at a specific location ID using indexing.

## 4. How do I access elements in a vector using their location ID in MATLAB?

You can access elements in a vector using their location ID by using indexing. For example, to access the element at location ID 5 in a vector called "myVector", you would use the syntax "myVector(5)". This will return the value at location ID 5 in the vector.

## 5. Is the location ID of an element in a vector the same as its index?

Yes, in MATLAB, the location ID of an element in a vector is the same as its index. The first element in a vector has a location ID of 1 and an index of 1, the second element has a location ID of 2 and an index of 2, and so on.