Hi, I would like to write an if statement where if RTcout<Ta , RTcout=Ta. The difficulty im having is that Ta has not been defined in the script but has been subbed into equations. Below is an example of the code:
Tcout1 = (subs(Tcout,{J,Ta,Vw},{numData1(2:25,6)',numData1(2:25,8)',numData1(2:25,12)'}));
RTcout = real(Tcout1);
Any help would be appreciated.

 채택된 답변

Star Strider
Star Strider 2019년 7월 26일

0 개 추천

Do the threshold operation before you do the substitution:
numData = randi(500, 1, 10); % Original Data
JData = numData; % Create New Data Vector
JData(Jdata < 200) = 0; % Threshold Or Substitute Data
syms a b J
v = a*b + J;
vnew = subs(v, {J,a,b},{numData', randi(9,1,10)',randi(9,1,10)'}) % Substitute Thresholded Data
It would be more illustrative with your code and data, however we do not have enough of that to use.

댓글 수: 4

Star Strider
Star Strider 2019년 7월 26일
Where is ‘1Day.xlsx’?
Can’t run your code without the file.
Thank you.
Try this (only the very last section copied and pasted here):
%%
hours = 0:23;
%%
Ta = numData1(2:25,8)';
RTcout = double(vpa(real(Tcout1)));
Tam = ones(size(RTcout,1),1) * Ta;
RTcout(RTcout < Ta) = Tam(RTcout < Ta);
% if RTcout <Ta;
% RTcout=Ta
% end
plot(hours,RTcout(2,:));
xlabel('Time of day')
That appears to do the replacements correctly. The only necessary change was to create ‘RTcout’ as a double array so that the replacement with non-symbolic ‘Ta’ would work. (The ‘Tam’ array creates a matrix from ‘Ta’ so the dimensions are the same.) The rest is just ‘logical indexing’.
rammah nagi
rammah nagi 2019년 7월 26일
Thank you very much
Star Strider
Star Strider 2019년 7월 26일
As always, my pleasure.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Language Fundamentals에 대해 자세히 알아보기

제품

릴리스

R2019a

태그

질문:

2019년 7월 26일

댓글:

2019년 7월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by