how to switch contents of two variables?

조회 수: 18 (최근 30일)
googo
googo 2013년 3월 24일
댓글: Walter Roberson 2017년 11월 21일
hey,
I want to write a program that returns the day diffrence between two specific dats. Now,, I want the second date to be the latter chronologicly. If the user type them otherwise I want to switch them. I'm very new at matlab, I tried this but I think It's not good...
if (date1(1)>date2(1)) && (date1(2)>date2(2)) % I assum it's the same year, date 1 and 2 is a 1X3 vectors.
date1=date2;
date2=date1;
end
what's the right way to do this? thank you very much!

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 3월 24일
temp_date=date1
date1=date2;
date2=temp_date;
  댓글 수: 4
Sai Vaddi
Sai Vaddi 2017년 11월 21일
how to perform the same code using simulink
Walter Roberson
Walter Roberson 2017년 11월 21일
Sai Vaddi:
Use two minmax blocks. Send both signals to both of them. Have one send out the min and the other send out the max. You can combine the two with a mux block afterwards if you want.

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

추가 답변 (1개)

Image Analyst
Image Analyst 2015년 11월 7일
Try deal() - it's MATLAB's version of a swap function:
[date2, date1] = deal(date1, date2) % Swap date1 and date2

카테고리

Help CenterFile Exchange에서 Time Series Objects에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by