How to Add Spaces in MatLab Output for Workshop 5, Exercise 3?

  • MATLAB
  • Thread starter Spectre32
  • Start date
  • Tags
    Matlab
In summary, the conversation is about adding spaces into an output and a code being used to calculate the volume of a piece of iron. The expert suggests using a for loop to create the desired output.
  • #1
Spectre32
136
0
I gott add spaces into this output, how in sweet gods name do i do this? Here is my code:

disp( '' )
disp( 'Solution to workshop 5, exercise 3 ')
disp( 'Calculate the volume of a piece of iron by determining the amount of')
disp( 'water displaced as it is submerged.')



Thanks
 
Physics news on Phys.org
  • #2
I'm confused what you're asking for...

what do you want the output to look like?
 
  • #3
Well when it's displayed.. it looks like this:

Solution to workshop 5, exercise 3
Calculate the volume of a piece of iron by determining the amount of
water displaced as it is submerged.

I want it to look like this:

Solution to workshop 5, exercise 3

Calculate the volume of a piece of iron by determining the amount of

water displaced as it is submerged.

---with space(s) inbetween the lines. I can't figure out how to do this
 
  • #4
Try this:

Code:
for a=1
   disp('a')
   disp(' ')
   disp(' ')
   disp('b')
end

It should output
Code:
a


b
 
  • #5
AH! Score. Thanks man, it's workin now!
 

What is the purpose of "MatLab display question"?

The "MatLab display question" is a command used in MatLab to display text or variables in the command window. It is useful for checking the values of variables and debugging code.

How do I use the "MatLab display question" command?

The "MatLab display question" command is used by typing "disp" followed by the text or variable you want to display in single quotes. For example, to display the text "Hello World", you would type "disp('Hello World')".

Can I display multiple lines of text using the "MatLab display question" command?

Yes, you can display multiple lines of text by using the escape character "\n" to indicate a new line. For example, "disp('Hello\nWorld')" would display "Hello" on the first line and "World" on the second line.

Can I use the "MatLab display question" command to display variables?

Yes, you can display variables by including them in the command within single quotes. For example, if you have a variable named "x" with a value of 5, you can use the command "disp('x = ', x)" to display "x = 5" in the command window.

Is there a way to format the output of the "MatLab display question" command?

Yes, you can use the sprintf function to format the output of the "MatLab display question" command. This allows you to control the number of decimal places, add leading zeros, and more. For example, "disp(sprintf('x = %.2f', x))" would display "x = 5.00" if x had a value of 5.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
752
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
7K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
19K
  • General Engineering
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
27
Views
7K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
2K
Back
Top