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...
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.
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...
Use MATLAB to create a script which solves for problem 5.9 in the book (5.11 in...
Use MATLAB to create a script which solves for problem 5.9 in the book (5.11 in the 4th edition). Given are the equations for the moment, as a function of x, starting from the leftmost side of the beam with x=0 and ending at the other end of the beam with x=12. This piecewise function together makes up the moment equation for the beam given. 0 ≤ ? ≤ 3 ?(?) = 265? − 5.56?3 , 3 < ? ≤...
Create a MATLAB script file to determine the given function is continuous or discontinuous at given...
Create a MATLAB script file to determine the given function is continuous or discontinuous at given interval (points).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT