Question

Write a MATLAB program to do the following: Receive 5 input values and store them into...

Write a MATLAB program to do the following:

  1. Receive 5 input values and store them into a single 1x5 array
  2. Receive another 2 input values and store them into a separate 1x2 array
  3. Add the scalar value 5 to each array value
  4. Store each array into 2 cells within one cell array
  5. Also store each array as separate elements within one struct
0 0
Add a comment Improve this question Transcribed image text
Answer #1

% Code:

close all; clear all; clc;

% Create 1st array with 5 elements
array1 = []; % starting empty array
fprintf("Input 5 values");
for i = 1:5
x = input(''); % Taking input
array1 = [array1 x]; % Concatenating input values to array1
end
fprintf("1st array")
disp(array1) % Print 1st array

% Create 2nd array with 2 elements
array2 = []; % starting empty array
fprintf("Input 2 values");
for i = 1:2
x = input(''); % Taking input
array2 = [array2 x]; % Concatenating input values to array2
end
fprintf("2nd array")
disp(array2) % Print 2nd array

array1 = array1 + 5; % Adding 5 to each element of first array
array2 = array2 + 5; % Adding 5 to each element of second array

fprintf("array1 after adding 5 ")
disp(array1) % Print array1 after adding 5
fprintf("array2 after adding 5 ")
disp(array2) % Print array2 after adding 5

% Creating cell array C with array1 and array2 as elements
C = {array1, array2};
fprintf("cell array")
disp(C) % print cell array

% Creating struct S with array1 and array2 as elements
S(1).array = array1;
S(2).array = array2;
fprintf("struct")
disp(S) % Print struct

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Sample run:

Add a comment
Know the answer?
Add Answer to:
Write a MATLAB program to do the following: Receive 5 input values and store them into...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 2. Write a program to do the following: • ask the user to input the size...

    2. Write a program to do the following: • ask the user to input the size of an array of integers and allocate space for the array • ask the user to input the integer values for the array and store these values into the array • calculate and display the sum and the average of elements of the array.

  • write a python program that reads in 5 numeric values,store them in an array ,then prints...

    write a python program that reads in 5 numeric values,store them in an array ,then prints them out in the reverse order that they were entered

  • I need help with the C++ for the following problem: Write a program that can store...

    I need help with the C++ for the following problem: Write a program that can store and output 5 integers, where the user can input its value into an array named arrayValue. The program should implement the following: 1. Calculate the sum and average of the array. 2. Output the content (value) that stored in the array of five elements. 3. Continue to ask the user to store for storing data into another array.

  • Question 7 10 points Save Write a Matlab or C program to store 12 temperature values...

    Question 7 10 points Save Write a Matlab or C program to store 12 temperature values in a day like per hour in°C in an array and display the temperature values and the average temperature value. example input: (22.4, 24, 28.2, 26.5, 23.7, 30, 31, 29.4. 28.4.27.3, 28, 29) TTT Art 3(12pt) T.E

  • Main topics: Files Program Specification: For this assignment, you need only write a single-file ...

    C program Main topics: Files Program Specification: For this assignment, you need only write a single-file C program. Your program will: Define the following C structure sample typedef struct int sarray size; the number of elements in this sanple's array floatsarray the sample's array of values sample Each sample holds a variable number of values, all taken together constitute a Sample Point Write a separate function to Read a file of delimited Sample Points into an array of pointers to...

  • Write a C program that initializes an integer array, and two scalar values a and b....

    Write a C program that initializes an integer array, and two scalar values a and b. Your program should multiply each elements of the array with a and add b to the product to form a new array output. Display the output array.

  • Q1. Write a program in Java         a. Create 2 separate arrays, of user defined values,...

    Q1. Write a program in Java         a. Create 2 separate arrays, of user defined values, of same size         b. Add these 2 arrays. ........................................................................................................................... Q2. Write a program in java (using loop) input any10 numbers from user and store in an array. Check whether each of array element is positive, negative, zero, odd or even number. ............................................................................................................................ Q3. Write a program in Java to display first 10 natural numbers. Find the sum of only odd numbers. .............................................................................................................................. Q4....

  • Please write program by using MATLAB Sum elements of ‘A’ as shown and store results in...

    Please write program by using MATLAB Sum elements of ‘A’ as shown and store results in an array ‘B’. Assume ‘A’ always has even number of elements. Eg A= [ 1 2 5 6 10 12] B= [ 1+12, 2+10, 5+6] Therefore output:B = [13, 12, 11]

  • Use DevC++ to implement a program that can store and output 5 integers, where the user...

    Use DevC++ to implement a program that can store and output 5 integers, where the user can input its value into an array named arrayValue. The program should implement the following: 1. Calculate the sum and average of the array. (5 points) 2. Output the content (value) that stored in the array of five elements. (10 points) 3. Continue to ask the user to store for storing data into another array(store and output 5 integers). (10 points) Prelude to Programming...

  • Use C++ to implement a program that can store and output 5 integers, where the user...

    Use C++ to implement a program that can store and output 5 integers, where the user can input its value into an array named arrayValue. The program should implement the following: 1. Calculate the sum and average of the array. (5 points) 2. Output the content (value) that stored in the array of five elements. (10 points) 3. Continue to ask the user to store for storing data into another array. (10 points)

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT