MATLAB: A Practical Introduction to Programming and Problem Solving
MATLAB: A Practical Introduction to Programming and Problem Solving
5th Edition
ISBN: 9780128163450
Author: ATTAWAY
Publisher: ELSEVIER
bartleby

Concept explainers

bartleby

Videos

Question
Book Icon
Chapter 8, Problem 8.1P
To determine

To write:

An expression that would display a random element from a cell array and a function that will receive one cell array as input argument and will display a random element from it.

Expert Solution & Answer
Check Mark

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,

 A = {41,'hiii', 1:4;'matlab', 10, 1:2:9}

The random element from the above array is,

ans=‘hiii’

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,

MATLAB: A Practical Introduction to Programming and Problem Solving, Chapter 8, Problem 8.1P , additional homework tip  1

MATLAB: A Practical Introduction to Programming and Problem Solving, Chapter 8, Problem 8.1P , additional homework tip  2

Therefore, the results are stated above.

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
0|0|0|0 - Consider the time series X₁ and Y₁ = (I – B)² (I – B³)Xt. What transformations were performed on Xt to obtain Yt? seasonal difference of order 2 simple difference of order 5 seasonal difference of order 1 seasonal difference of order 5 simple difference of order 2
Calculate the 90% confidence interval for the population mean difference using the data in the attached image. I need to see where I went wrong.
Microsoft Excel snapshot for random sampling: Also note the formula used for the last column 02 x✓ fx =INDEX(5852:58551, RANK(C2, $C$2:$C$51)) A B 1 No. States 2 1 ALABAMA Rand No. 0.925957526 3 2 ALASKA 0.372999976 4 3 ARIZONA 0.941323044 5 4 ARKANSAS 0.071266381 Random Sample CALIFORNIA NORTH CAROLINA ARKANSAS WASHINGTON G7 Microsoft Excel snapshot for systematic sampling: xfx INDEX(SD52:50551, F7) A B E F G 1 No. States Rand No. Random Sample population 50 2 1 ALABAMA 0.5296685 NEW HAMPSHIRE sample 10 3 2 ALASKA 0.4493186 OKLAHOMA k 5 4 3 ARIZONA 0.707914 KANSAS 5 4 ARKANSAS 0.4831379 NORTH DAKOTA 6 5 CALIFORNIA 0.7277162 INDIANA Random Sample Sample Name 7 6 COLORADO 0.5865002 MISSISSIPPI 8 7:ONNECTICU 0.7640596 ILLINOIS 9 8 DELAWARE 0.5783029 MISSOURI 525 10 15 INDIANA MARYLAND COLORADO
Knowledge Booster
Background pattern image
Statistics
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, statistics and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Algebra & Trigonometry with Analytic Geometry
Algebra
ISBN:9781133382119
Author:Swokowski
Publisher:Cengage
Text book image
Algebra: Structure And Method, Book 1
Algebra
ISBN:9780395977224
Author:Richard G. Brown, Mary P. Dolciani, Robert H. Sorgenfrey, William L. Cole
Publisher:McDougal Littell
Text book image
College Algebra
Algebra
ISBN:9781337282291
Author:Ron Larson
Publisher:Cengage Learning
ALGEBRAIC EXPRESSIONS & EQUATIONS | GRADE 6; Author: SheenaDoria;https://www.youtube.com/watch?v=fUOdon3y1hU;License: Standard YouTube License, CC-BY
Algebraic Expression And Manipulation For O Level; Author: Maths Solution;https://www.youtube.com/watch?v=MhTyodgnzNM;License: Standard YouTube License, CC-BY
Algebra for Beginners | Basics of Algebra; Author: Geek's Lesson;https://www.youtube.com/watch?v=PVoTRu3p6ug;License: Standard YouTube License, CC-BY
Introduction to Algebra | Algebra for Beginners | Math | LetsTute; Author: Let'stute;https://www.youtube.com/watch?v=VqfeXMinM0U;License: Standard YouTube License, CC-BY