Find a value in a matrix with specified interval
7 views (last 30 days)
Show older comments
Hello all,
I have some problems with my matlab syntax. My goal: I'm trying to build a function where I can calculate the ristime out of my collection of data(matrix). For this I would like to search in a defined intervall for my 10 % Amplitude and 90% Amplitude. My Code:
function Risetime()
v = load('D:\MATLAB\Beispiele\Funktionen\Messkurve einer Entladung\C1MP1000000.dat');
t = v(:,1); %Read the values of time axis
a = v(:,2); %Read the values of amplitude axis
ai = a/0.1; % Calculate the current values
vi = [t ai]; % Build a Current Matrix
h = plot(t,ai);
hold all;
axis([-0.5e-7 1.5e-7 0 7]);
%Seeking for the upper limit
Imax = max(ai); % Imax oder Ip
[y zeile] = min(abs(ai - Imax)); % Die Zeile ermitteln
tmax = vi(zeile,1);
uL = [tmax, Imax]; % Upper Limit
I_10 = 0.1 * Imax; % Defining the Value for 10%
I_90 = 0.9 * Imax; % Defining the Value for 90%
% Suche der unteren Intervall Grenze min = [tmin, Imin]
% Leichteste Methode
% [tmin zeile] = find(t == tmin)
% Seeking for the lowest limit
tmin = 0;
[x zeile] = min(abs(t-tmin));
Imin = vi(zeile,2);
lL = [x, Imin]; %lowest limit
%Search for the Values for the values compared to I_10 and I_90 in the defined area of my matrix "vi"
for i = 1
ans = min(abs(vi(i,2)-I_10))
ans = find(uL < vi & vi < oL)
end
Now If I try to run my m file it gives me an error:
??? Error using ==> lt
Matrix dimensions must agree.
Error in ==> Risetime at 41
ans = find(uL < vi & vi < oL)
Could somone help me out!
Thank you!
Regards
Saqib Inam
1 Comment
Thomas
on 26 Apr 2012
Do you mean you want to find all your values of ai in vi which lie inbetween I_10 and I_90?
Accepted Answer
Walter Roberson
on 26 Apr 2012
Your uL and oL are vectors (two elements each), and your vi is a vector with more than 2 elements. You cannot compare a vector with two elements to a vector with more than 2 elements using a single "<" comparison.
I cannot determine your intention in those statements.
2 Comments
Walter Roberson
on 2 May 2012
A syntax such as
find(uL < vi & vi < oL)
is fine for searching for the elements of vi that are between uL and oL, but _only_ if uL and oL are scalar values.
Your present uL and oL are vector values. You are trying to compare a vector to a vector, and that is not defined.
Perhaps you mean something like
find(uL(1) < vi & vi < oL(1))
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!