Correctly displaying result on Matlab

  • Thread starter alba_ei
  • Start date
  • Tags
    Matlab
In summary, the conversation is about sorting months in a calendar and the attempt at creating a solution using MATLAB. The code provided includes creating a character array of months and sorting them in alphabetical order. However, the final lines of code do not produce the desired output.
  • #1
alba_ei
39
1

Homework Statement


33ld01i.png


The Attempt at a Solution


Attempt 1
Code:
clc;    
clear;
Months=char('January','February','March','April','May','June','July','August','September','October','November','December');
CalSort=char(sortrows(Months));
Cell={CalSort};
disp([CalSort(:,1:6) CalSort(:,7:12)])

Executing CalSort=char(sortrows(Months))
Code:
CalSort =
April    
August   
December 
February 
January  
July     
June     
March    
May      
November 
October  
September

But the two last lines of codes doesn't give me the wanted result.
 
Physics news on Phys.org
  • #2
Attempt 2clc; clear;Months=char('January','February','March','April','May','June','July','August','September','October','November','December');CalSort=char(sortrows(Months));Cell={CalSort};disp({CalSort})Executing CalSort=char(sortrows(Months))CalSort =April August December February January July June March May November October SeptemberBut the two last lines of codes doesn't give me the wanted result.
 

FAQ: Correctly displaying result on Matlab

How can I display the result of my calculations in MATLAB?

To display the result of your calculations in MATLAB, you can use the disp function. This function will print the value of the expression or variable to the command window. For example, if you have a variable x with a value of 5, you can use disp(x) to display the value 5 in the command window.

Can I customize the way the result is displayed in MATLAB?

Yes, you can customize the way the result is displayed in MATLAB using formatting options. For example, you can specify the number of decimal places to display or use scientific notation. You can also add text or symbols to the result using the fprintf function.

How can I save the result of my calculations in MATLAB?

To save the result of your calculations in MATLAB, you can use the save function. This function allows you to save the value of a variable or expression to a file. You can also specify the format of the file, such as a text file or a MATLAB data file.

Can I plot the result of my calculations in MATLAB?

Yes, you can plot the result of your calculations in MATLAB using the plot function. This function allows you to create different types of plots, such as line plots, scatter plots, and histograms. You can also customize the appearance of the plot by adding labels, titles, and changing the color or style of the plot.

How can I display the result of my calculations in a graphical user interface (GUI) in MATLAB?

To display the result of your calculations in a GUI in MATLAB, you can use the uicontrol function. This function allows you to create different types of user interface elements, such as buttons, sliders, or text boxes. You can then use these elements to display the result of your calculations or allow the user to input values for the calculations.

Similar threads

Replies
12
Views
3K
Replies
7
Views
1K
Replies
29
Views
4K
Replies
6
Views
8K
Replies
2
Views
2K
Replies
45
Views
7K
Back
Top