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

1 visualizzazione (ultimi 30 giorni)
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 Commenti
Stephan
Stephan il 18 Mag 2021
Please share code, not pictures of code.

Accedi per commentare.

Risposta accettata

Rik
Rik il 18 Mag 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.

Più risposte (0)

Categorie

Scopri di più su Get Started with MATLAB in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by