Register to reply

MATLAB Help - Comparing values/Indexing

by nvalia
Tags: compare, indexing, matlab
Share this thread:
nvalia
#1
Mar18-10, 10:30 PM
P: 4
1. The problem statement, all variables and given/known data

I am very, very new to MATLAB, and can't seem to figure out this seemingly simple problem.

Given a t-array and a y-array for a decaying exponential function, my task is to find the first relative maximum in the graph without using Matlab's preset relative max. functions. I'm attempting to do this by comparing y-values at a certain "t" to y-values at "t0" and "t1" (before and after "t"). I'm using indexing, for loops, etc.


2. Relevant equations

N/A


3. The attempt at a solution

function[max,t_max] = relMax(t,y)
for i = 1:.001:length(t);
y(:,i+1) = y;
y0 = y(:,i);
y1 = y(:,i+2);
if (y0<y && y>y1)
max = y;
disp(max)
t_max = t;
disp(t)
break
end
end

---

Clearly I am making some kind of stupid mistake here. I don't really know how to use indexing very well, and it's causing me problems.

Thanks in advance!
Phys.Org News Partner Science news on Phys.org
Physical constant is constant even in strong gravitational fields
Montreal VR headset team turns to crowdfunding for Totem
Researchers study vital 'on/off switches' that control when bacteria turn deadly
CEL
#2
Mar19-10, 08:27 AM
P: 639
Quote Quote by nvalia View Post
1. The problem statement, all variables and given/known data

I am very, very new to MATLAB, and can't seem to figure out this seemingly simple problem.

Given a t-array and a y-array for a decaying exponential function, my task is to find the first relative maximum in the graph without using Matlab's preset relative max. functions. I'm attempting to do this by comparing y-values at a certain "t" to y-values at "t0" and "t1" (before and after "t"). I'm using indexing, for loops, etc.


2. Relevant equations

N/A


3. The attempt at a solution

function[max,t_max] = relMax(t,y)
for i = 1:.001:length(t);
y(:,i+1) = y;
y0 = y(:,i);
y1 = y(:,i+2);
if (y0<y && y>y1)
max = y;
disp(max)
t_max = t;
disp(t)
break
end
end

---

Clearly I am making some kind of stupid mistake here. I don't really know how to use indexing very well, and it's causing me problems.

Thanks in advance!
Indexes must be integers. You should make your loop as
for i = 1: length(t)

0.001 is the increment in t, not in the index.
nvalia
#3
Mar19-10, 11:19 AM
P: 4
Thank you! I figured out what I was doing wrong. :)


Register to reply

Related Discussions
Chemistry: Comparing the Rf values of carotene and lycopene? Biology, Chemistry & Other Homework 0
Urgent help needed for question on electrolysis & comparing Eo values Chemistry 2
Matlab: Figure, Mouse, Coordinate Values Math & Science Software 0
[Matlab] How to save the obtained values. Math & Science Software 1
Indexing a website Computing & Technology 13