Question

The following code must be written in Matlab I want to print the following in Matlab...

The following code must be written in Matlab

I want to print the following in Matlab (x1,x2, x3, ....xn) = (0.33333, 0.33333, 0.33333,....) That is for n variables . The whole thing should be on the same line.

I need to use fprintf and write out the coordinates with 5 decimal places of variable xn = (0.33333, 0.33333, 0.33333,....)

Thanks!

Homework Answers

Answer #1

I have provided the solution according to the problem statement, if you have any problem ask in the comments, i will help you.

Copy and Paste code:

function printInOneLine(n)

X = ones(1,n)*0.333333;

fprintf("%.5f",X); %.5f is used to set the precision to 5 decimal places

end

Output:

printInOneLine(15)

0.333330.333330.333330.333330.333330.333330.333330.333330.333330.333330.333330.333330.333330.333330.33333

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
The following code must be written in matlab. I have a list of inidices say L...
The following code must be written in matlab. I have a list of inidices say L = [1,2,5,10,6,7,] I want to loop through indices in a for loop from i=1:n , n=100 but I must skip all indices that are not in the list L How can I do this if I am not allowed to use the ismember function. Thankse
Code in Matlab. I need to make a diamond shape with * I get part of...
Code in Matlab. I need to make a diamond shape with * I get part of it with the code below. Instructions are: " Given the value of N print diamond of N + (N-1) rows. For example, if N = 5 it should print a diamond." clc clear n = input ('number of rows \n') o = input ('number of inverted rows \n') t = (o-1) for i = 1:n for k = 1:n-i fprintf (' '); end for...
The following code must be written in matlab How to convert a 4d unit8 matrix of...
The following code must be written in matlab How to convert a 4d unit8 matrix of size 28 28 1 50000 in Matlab to a matrix of size 784*5000 Give an example that clearly solves this issue. Thanks
MATLAB question dont change subject Give the matlab code for the following, i need to find...
MATLAB question dont change subject Give the matlab code for the following, i need to find the critical damping coefficient of a system User will enter mass and stiffness and the code will print the critical damping coefficient Give working code or else i will badly downvote
I need MATLAB code no handwritten solution required. Write a MATLAB script to solve the following...
I need MATLAB code no handwritten solution required. Write a MATLAB script to solve the following equations using the Cramer’s rule, and compare your results with MATLAB’s root finding method ( 25 pts. ). 8x1 − 2x2 − 1x3 = 5 − 2x1 + 9x2 − 4x3 − x4 = 2 − x1 − 3x2 + 7x3 − x4 − 2x5 = 1 − 4x2 − 2x3 + 12x4 − 5x5 = 1 − 7x3 − 3x4 − 15x5 =...
I have already written a MATLAB code to filter noise from a particular audio file however...
I have already written a MATLAB code to filter noise from a particular audio file however the resulted audio is not playing I use this code snippet: presult = audioplayer(fOut, fs); presult.play; the fout is fOut = filter(b, a, f); I do not know what i am doing wrong as the output playing is still the initial sound not thr noise filtered one. Please help deadline is due in hours. Thanks in advance
How can i make this lunix code print 3 numbers in reverse it must be in...
How can i make this lunix code print 3 numbers in reverse it must be in printStars format and no loops Here is the code i have but can figure out how to reverse the numbers #include<stdio.h> void printStars(int n) { if (n>0){ printf(""); printStars(n-1); } } int main() { int n; int b; int c; printf("Enter 3 numbers to reverse "); scanf("%d",&n,&b,&c); printf("your reversed numbers are %d",n); printStars(n); return 0;
Use either R or Excel for the following. Provide the formulas or code that you are...
Use either R or Excel for the following. Provide the formulas or code that you are using. Let x1 be a random variable that is N(100, 225). Let x2 be a random variable that is U(50,150) and let x3 be a random variable that is U(500,1500). Set Y = (X1)(X2)/ (X3) a) Use R to create 500 random numbers of each type (X1, X2, X3 and Y). b) Estimate P(0.1 < Y < 0.25) c) Estimate E(Y) and the Standard...
Solve the following system of equations using LU factorization with partial pivoting: 2x1 − 6x2 −...
Solve the following system of equations using LU factorization with partial pivoting: 2x1 − 6x2 − x3 = −38 −3x1 − x2 + 7x3 = −34 −8x1 + x2 − 2x3 = −40 I would like to write a matlab code to solve the problem without using loops or if statements. All i want is a code to swap the rows. I can solve the rest. Thank you in advance.
5.8 Explain how the following conditions can be represented as linear constraints using binary variables. (a)...
5.8 Explain how the following conditions can be represented as linear constraints using binary variables. (a) Either x1 + x2 ? 3 or 3x1 + 4x2 ? 10 (b) Variable x2 can assume values 0, 4, 7, 10, and 12 only (c) If x2 ? 3, then x3 ? 6; Otherwise x3 ? 4 (assume x2 and x3 are integers) (d) At least 2 out of the following 5 constraints must be satisfied: x1 + x2 <=7 x1 ? x2...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT