Clear Filters
Clear Filters

how to switch contents of two variables?

19 views (last 30 days)
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!

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 24 Mar 2013
temp_date=date1
date1=date2;
date2=temp_date;
  4 Comments
Sai Vaddi
Sai Vaddi on 21 Nov 2017
how to perform the same code using simulink
Walter Roberson
Walter Roberson on 21 Nov 2017
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.

Sign in to comment.

More Answers (1)

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

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!