Two Matrices comparison with incrementing column of 2nd matrix
1 view (last 30 days)
Show older comments
Maisam Zaidi
on 5 Apr 2022
Commented: Maisam Zaidi
on 6 Apr 2022
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
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?
Accepted Answer
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)
8 Comments
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.
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!