Concept explainers
To write:
An expression that would display a random element from a cell array and a
Answer to Problem 8.1P
Solution:
The file is,
%MATLAB code to create a cell array and perform the operations.
%cell array file.
X = {41,'hiii', 1:4;'matlab', 10, 1:2:9}
%define a cell array.
X{randi(numel(X))}
%define the random element from the cell array.
Z = X'
%get the transpose of the cell array.
Z{randi(numel(Z))}
%define the random element from the above cell array.
%end of cell array file
%The cell array file should be placed in the same folder.
The function file is,
%MATLAB code to create a cell array and get the random element from the cell arary.
%function file.
function A = randomelement(cell)
A = cell{randi(numel(cell))};
end
%end of function file
%The function file should be placed in the same folder
Explanation of Solution
Consider the cell array is,
The random element from the above array is,
MATLAB Code:
clc
clear all
close all
%MATLAB code to create a cell array and perform the operations.
%cell array file.
X = {41,'hiii', 1:4;'matlab', 10, 1:2:9}
%define a cell array.
X{randi(numel(X))}
%define the random element from the cell array.
Z = X'
%get the transpose of the cell array.
Z{randi(numel(Z))}
%define the random element from the above cell array.
%end of cell array file
%The cell array file should be placed in the same folder.
%MATLAB code to create a cell array and get the random element from the cell arary.
%function file.
function A = randomelement(cell)
A = cell{randi(numel(cell))};
end
%end of function file
%The function file should be placed in the same folder
Save the MATLAB cell array file with name, chapter8_54793_8_1P.m and a function file with the name of randomelement.m in the current folder. Execute the function by typing the function name at the command window to generate output.
Result:
The results are,
Therefore, the results are stated above.
Want to see more full solutions like this?
Chapter 8 Solutions
MATLAB: A Practical Introduction to Programming and Problem Solving
- Evaluate f 8tVt2 – 1 dtarrow_forwardA witness to a hit-and-run accident told the police that the license number contained the letters RQ followed by 5 digits, the first three being 7, 9 and 4. If the witness cannot recall the last 2 digits, but is certain that all 5 digits are different, find the maximum number of automobile registrations that the police may have to check. C The maximum number of automobile registrations that the police may have to check is (Type a whole number.)arrow_forwardFind A.arrow_forward
- When the robot makes a turn, it would be useful to have an operation to perform on d to represent this turn. This is because after making a turn, the new value of d will depend on the old value of d. Complete the table for the new values of d if the robot is turning left or right. Then determine an expression in terms of d that will give the new position if the robot turns left and another expression if the robot turns right. Type these expressions in the last row of the table.arrow_forwardJoe's Assignment Average is 80, his Quiz Average is 70, and he got a 50 on the Midterm Exam. In order to get a grade of 'B' for the class, he needs a weighted average of 74. What is the minimum grade Joe needs to get on the final exam in order to get a 'B' for the class? (Enter your answer as a single integer with no words.) AVarrow_forwardEvaluate.arrow_forward
- A company that sells its product on their website would like to improve the sales by making the webpage with product info more attractive. Current version (call it version A) and a new version (call it version B) are compared. A JavaScript code randomly chooses one of the two versions of the website to load to each customer that clicks on the link to the page about the product. Each version of the page has Buy button that leads the customer to purchase the product online. The company would like to test whether the new version (B) is better than the old one (A) by comparing the true probabilities pA and PB of purchasing the product for a randomly chosen visit of each website. Let Pд be probability that a randomly chosen visitor of website version A buys the product from the website. Similarly, let pg be the corresponding probability for version B. Let n₁ and n₂ be sample sizes of the visitors of versions A and B, respectively. Also, denote by X1 and X2 the numbers of visitors in the two…arrow_forwardPlease box answerarrow_forwardPlease Answer thisarrow_forward
- Algebra & Trigonometry with Analytic GeometryAlgebraISBN:9781133382119Author:SwokowskiPublisher:CengageAlgebra: Structure And Method, Book 1AlgebraISBN:9780395977224Author:Richard G. Brown, Mary P. Dolciani, Robert H. Sorgenfrey, William L. ColePublisher:McDougal Littell