Question

In: Computer Science

Q22 Variable s is defined as a string vector. We display the first a couple of...

Q22 Variable s is defined as a string vector. We display the first a couple of elements: s = [ ′′height′′ , “12.5” , “weight ′′ , ′′103-9′′ , ′′NWD′′, ... ].

Code to do the following.

  1. replace all elements “height” with “dimension” for s. Solve this using loop
  2. replace all elements “height” with “dimension” for s. Solve this without using loop
  3. create a new character vector s1, which concatenate all elements of s horizontally. That is, s1 = ′′height12.5weight 103-9NWD...”.

I need help to solve this in MATLAB programming please.....

Solutions

Expert Solution

s = [ "height" , "12.5" , "weight" , "103-9" , "NWD","height"];
%replace all elements "height” with “dimension” for s. Solve this using loop
for i=1:length(s)
if s(i)=="height"
s(i)="dimension";
end
end
s
s = [ "height" , "12.5" , "weight" , "103-9" , "NWD","height"];
%replace all elements "height” with “dimension” for s. Solve this without using loop
s(s=="height")="dimension"
s = [ "height" , "12.5" , "weight" , "103-9" , "NWD","height"];
%create a new character vector s1, which concatenate all elements of s horizontally. That is, s1 = ′′height12.5weight 103-9NWD...".
s1='';
for i=s
s1=[s1,char(i)];
end
s1


Related Solutions

Define a sequence of string of 0’s and 1’s: 1 The first string, s0, is just...
Define a sequence of string of 0’s and 1’s: 1 The first string, s0, is just the empty string "". The second string, s1, is 1. The third, fourth, fifth, . . . strings are defined as follows: si = si−11ti−1 where ti−1 is the reverse of si−1 with all 0s replaced by 1s and all 1s replaced by 0s. The first few strings are s0 = "", s1 = 1, s2 = 110, s3 = 1101100, s4 = 110110011100100....
Declare a string variable and initialize it with your first name ( in C++)
Declare a string variable and initialize it with your first name ( in C++)
Write a script that will first initialize a string variable that will store x and y...
Write a script that will first initialize a string variable that will store x and y coordinates of a point in the form ‘x 3.1 y 6.4’. Then, use string manipulating functions to extract the coordinates and plot them. ANS % create a string variable of the form 'x 3.1 y 6.4' % extract the x and y coordinates and plot str = 'x 2.3 y 4.5'; [letter rest] = strtok(str); [x rest] = strtok(rest); [letter rest] = strtok(rest); y...
Proof: Let S ⊆ V be a subset of a vector space V over F. We...
Proof: Let S ⊆ V be a subset of a vector space V over F. We have that S is linearly dependent if and only if there exist vectors v1, v2, . . . , vn ∈ S such that vi is a linear combination of v1, v2, . . . , vi−1, vi+1, . . . , vn for some 1 ≤ i ≤ n.
Chubbs Inc.’s manufacturing overhead budget for the first quarter of 2020 contained the following data. Variable...
Chubbs Inc.’s manufacturing overhead budget for the first quarter of 2020 contained the following data. Variable Costs Fixed Costs Indirect materials $11,100 Supervisory salaries $36,700 Indirect labor 11,000 Depreciation 6,100 Utilities 7,700 Property taxes and insurance 7,400 Maintenance 5,500 Maintenance 4,900 Actual variable costs were indirect materials $14,800, indirect labor $9,200, utilities $9,300, and maintenance $5,200. Actual fixed costs equaled budgeted costs except for property taxes and insurance, which were $8,400. The actual activity level equaled the budgeted level. All...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT