Extract Numerator and Denominator of a vector (ratio)

2 views (last 30 days)
Hello Everyone,
I appreciate your helps in advance as I am a beginner in MATLAB!
I have a matrix and I should measure a ratio of a simple variable (it is a signal) and I need separate numerators and denominators (separated vectors) for next steps. My code is below. Thank you!
clc;
clear all;
close all;
%.....................................................................
data=xlsread('1');
amp=data(:,2);%us/f
time=data(:,1);%ms
t=time(1:1:end);% distans approximately 1 ms
am=amp(1:1:end);
l=length(t);
for i=1:l
if am(i)==-999.25
am(i)=am(i-1);
end
end
for j=2:l
r(j)=(am(j)-am(j-1))/(am(j)+am(j-1));
end

Accepted Answer

Scott MacKenzie
Scott MacKenzie on 13 Jun 2021
Edited: Scott MacKenzie on 13 Jun 2021
It is not entirely clear what you are trying to do. Your 1st for-loop does nothing, since all the values are positive. However, if I understand correctly, your second for-loop reveals how you want to spit the signal into terms for the numerator (us) and denominator (f) terms. If that's correct, then, instead of a single vector r, you likely want separate vectors, us and f. Given this, here is what I put together:
data = readmatrix('https://www.mathworks.com/matlabcentral/answers/uploaded_files/651850/01.xlsx');
amp = data(:,2); % signal (us/f)
time = data(:,1); % time (1 ms intervals, not needed)
% this is equivalent to your second for-loop (except separating the terms)
us = amp(2:end) - amp(1:end-1);
f = amp(2:end) + amp(1:end-1);
tiledlayout(2,1);
nexttile;
plot(amp);
xlabel('Time (ms)');
ylabel('Signal');
nexttile;
p1 = plot(f);
hold on;
p2 = plot(us);
xlabel('Time (ms)');
ylabel('Signal (separated)');
legend({'f' 'us'}, 'location', 'east');
  13 Comments
Maria Amr
Maria Amr on 14 Jun 2021
Yes sir. You are totally right. This is aeismic data (a layered earth) and is not original data. Now, I understood how I should use the output of the us and f. Your explanation is so useful! Appreciated!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!