Question

In: Electrical Engineering

(MATLAB) Write a script that would create a 3x5 matrix of random integers and write this...

(MATLAB)

Write a script that would create a 3x5 matrix of random integers and write this new matrix to a file called “Assignment3_Question5.dat”.

Solutions

Expert Solution

MATLAB code:

clc;clear all;
% Let us take range of integers [0,10]
% [0,10] indicates minimum value=0 and maximum value=10
% size 0f matrix [3,5]
disp('The generated matrix is')
M = randi([0,10],[3,5])
% Creating file to be written to
fileName = fopen('Assignment3_Question5.dat','w');
% Writing data to file
fprintf(fileName, '%f %f %f %f %f\n', M.');
% Closing
fclose(fileName);

disp('data stored in Assignment3_Question5.dat is')
%Opening file to read
type Assignment3_Question5.dat

MATLAB result: (in commond window)

The generated matrix is

M =

5 4 8 7 3
7 6 0 7 3
6 3 0 6 9

data stored in Assignment3_Question5.dat is

5.000000 4.000000 8.000000 7.000000 3.000000
7.000000 6.000000 0.000000 7.000000 3.000000
6.000000 3.000000 0.000000 6.000000 9.000000

Screenshot of Assignment3_Question5.dat:


Related Solutions

Matlab script that uses loops to create a multiplication table (matrix) where the user enters 'n'...
Matlab script that uses loops to create a multiplication table (matrix) where the user enters 'n' (nxn chart).
Write a Matlab script that computes the element level stiffness matrix and force vector for linear...
Write a Matlab script that computes the element level stiffness matrix and force vector for linear elasticity.
The language is MATLAB Write a function that will generate three random integers, each in the...
The language is MATLAB Write a function that will generate three random integers, each in the inclusive range from 10 to 80. It will then return a string consisting of the three integers joined together, and also a character vector consisting of the three integers joined together. For example, if the random integers are 11, 29, and 76, the string that is returned will be "112976" and the character vector that is returned will be '112976'. I'm really confused on...
Create a random matrix of size 10x10, of integers between 1 and 1000, and use nested...
Create a random matrix of size 10x10, of integers between 1 and 1000, and use nested for loops over the elements of the matrix to find the number of prime elements , as well as the sum of the prime elements in the matrix. You can use MATLAB's built-in function isprime to check if an element is a prime number. You should have these variable: cnt (counts the number of prime elements) sm (sum of prime elements) In the command...
MATLAB: Write as a script in the editor window of matlab. Quadratic roots. Write a program,...
MATLAB: Write as a script in the editor window of matlab. Quadratic roots. Write a program, quadroots.m, for finding the roots of the second- order polynomial ax2 + bx + c. Use the quadratic equation. The inputs are the coefficients a,b, and c and the outputs are z1 and z2. The program should produce (exactly) the following output in the Command window when run with (a, b, c) = (1, 2, −3):
Write a Matlab function for a matrix that takes in a matrix in echelon form and...
Write a Matlab function for a matrix that takes in a matrix in echelon form and will return the row canonical form. The function cannot use rref, or any other matlab built in functions.
MATLAB is program Respond fast please a quiz Create a MATLAB script. Using nested for loops,...
MATLAB is program Respond fast please a quiz Create a MATLAB script. Using nested for loops, evaluate the multivariable function: z = sin ⁡ ( x ) cos ⁡ ( y ) for x between -4 and 4 in steps of 1 y between -2 and 2 in steps of 1 Display the matrix z Cut and paste the following into a word doc and submit to this question. Your script code Your input Your output
IN MATLAB, Create a 8x8 magic matrix. Then use MATLAB built in function, sum, to calculate...
IN MATLAB, Create a 8x8 magic matrix. Then use MATLAB built in function, sum, to calculate the sum of each column. Use subscript notation to find the 6th element and the last element of each magic square. Find the maximum of all the elements in each magic square.
write a matlab script for double mass spring system with animation.
write a matlab script for double mass spring system with animation.
Part A: Write a MATLAB script to find the volume of the cylinder in gallons, as...
Part A: Write a MATLAB script to find the volume of the cylinder in gallons, as well as the tank dimensions in feet. Assume that the initial measurements are 7 meters in diameter and 11 meters tall. Display your final answers to the screen using disp and a statement without a semicolon, e.g. write the following into your script disp(‘The capacity in U.S. gallons is:’), capacity, where capacity is a variable that you defined in preceding calculations. Part B: In...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT