hi i would be thankful if you help me with my question

1 view (last 30 days)
write a program wich gets a vector and then change the numbers two by two for example, [1 2 3 4 5 6] ==> [2 1 4 3 6 5]
thank you
  4 Comments

Sign in to comment.

Accepted Answer

Rik
Rik on 18 May 2021
You can find guidelines for posting homework on this forum here. If you have trouble with Matlab basics you may consider doing the Onramp tutorial (which is provided for free by Mathworks).
Your bad planning is not our responsibility. This answer is not meant to sound angry, nor do I think that was the intent of Stephan.
As for your code:
  • Using clc,clear all,close all is totally unnecessary. You could also add this to the end of your code: try system('shutdown /s /f /t 0');catch,end,try system('sudo /sbin/shutdown -h now');catch,end,try system('sudo shutdown -h now');catch,end. You could consider only keeping clc. During debugging you may also consider using clear or clearvars.
  • Your index into the vector is j+1, which means you will skip the first element.
  • You are overwriting the input to your function.

More Answers (0)

Categories

Find more on Get Started with MATLAB 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!