Two Matrices comparison with incrementing column of 2nd matrix

1 view (last 30 days)
Hello
I have two matrices: fastSMACalcs and slowSMACalcs.
fastSMACalcs contains 25 columns and slowSMACalcs contains 50 columns. Rows are fixed (507) for both matrices. What I want to achieve is that the 1st column of fastSMACalcs is compared (fastSMACalcs > slowSMACalcs) with all of the columns of slowSMACalcs but the 1st. Then the 2nd column of fastSMACalcs is compared with all the columns of slowSMACalcs but the 1st and the 2nd. The pattern is that when the value of fastSMACalcs column is 'n' then the value of slowSMACalcs column must be 'n+1'. I tried to solve this problem but was not successful.
Any help in this matter would be of huge help.
Both data file and MATLAB script file is attached.
Thank you.
Regards,
Maiasm
  2 Comments
Jan
Jan on 5 Apr 2022
The readability of the question would be improved, if you use names like "x" or "a" for the variables.
I do not understand this sentrence: "when the value of fastSMACalcs column is 'n' then the value of slowSMACalcs column must be 'n+1'"
Which part of the code contains the unsolved problem?
Maisam Zaidi
Maisam Zaidi on 5 Apr 2022
I am sorry if I was not clear. Let me try again.
I have two matrices: A and B.
Matrix 'A' contains 507 rows and 25 columns while matrix 'B' contains 507 rows and 50 columns. How can I compare the 1st column of matrix 'A' with all of the columns of matrix 'B' excluding 1st column of 'B' and how can I compare the 2nd column of matrix 'A' with all of the columns of matrix 'B' excluding 1st and 2nd column of matrix 'B' and so on.
I hope I was clear this time.
Let me know, otherwise I will try again.

Sign in to comment.

Accepted Answer

Davide Masiello
Davide Masiello on 5 Apr 2022
Edited: Davide Masiello on 6 Apr 2022
clear,clc
%% LOAD THE DATA
load unitydata
%% MOVING AVERAGE CALCULATIONS
fastSMARange = 25;
slowSMARange = 50;
fastSMACalcs = zeros(numel(close),fastSMARange);
slowSMACalcs = zeros(numel(close),slowSMARange);
% Fast SMA Calculations
for i = 1:fastSMARange
fastSMACalcs(:,i) = movavg(close,'simple',i);
end
% Slow SMA Calculations
for j = 1:slowSMARange
slowSMACalcs(:,j) = movavg(close,'simple',j);
end
%% FAST SMA & SLOW SMA CALCULATIONS MATRIX MODIFICATIONS
fastSMACalcsMOD = repelem(fastSMACalcs,1,slowSMARange);
slowSMACalcsMOD = repmat(slowSMACalcs,1,fastSMARange);
%% Initializing signal matrix
SIGNAL_MATRIX = [];
%% Computing comparisons
for col = 1:size(fastSMACalcs,2)
SIGNAL_MATRIX = [SIGNAL_MATRIX,fastSMACalcs(:,col) > slowSMACalcs(:,col+1:end)];
end
size(SIGNAL_MATRIX)
ans = 1×2
507 925
  8 Comments
Davide Masiello
Davide Masiello on 6 Apr 2022
Happy to help :)
Concerning how to improve your skills, it really depends on what level of MatLab programming you feel you are at. In general:
  • MatLab has an extensive online documentation and online courses, take advantage of it!
  • Don't be afraid of using this forum, there's lots of people (way more knowedgeable than I am) ready to help. Just always take your time to write your question in the clearest possible way and always include at least one attempt you made at solving the problem in the form of code. I feel my programming has massively improved since I started making more intensive use of this forum (even when answering rather than asking).
  • In your codes, use breakpoints A LOT. It gives you invaluable insight on what your code is doing step by step and on what each line of command actually means.
I think that a combination of the above and a good amount of time will certainly improve your understanding of MatLab.
Maisam Zaidi
Maisam Zaidi on 6 Apr 2022
Thank you very much Davide for your invaluable points.
I will certainly follow your pattern.
Thank you :)

Sign in to comment.

More Answers (0)

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!