Two Matrices comparison with incrementing column of 2nd matrix

1 次查看(过去 30 天)
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 个评论
Jan
Jan 2022-4-5
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 2022-4-5
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.

请先登录,再进行评论。

采纳的回答

Davide Masiello
Davide Masiello 2022-4-5
编辑:Davide Masiello 2022-4-6
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 个评论
Davide Masiello
Davide Masiello 2022-4-6
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 2022-4-6
Thank you very much Davide for your invaluable points.
I will certainly follow your pattern.
Thank you :)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by