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
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?
采纳的回答
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)
8 个评论
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!