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
  • 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....

  • Java Program Create a class to store an array of with enough space to store 10 integer values. Us...

    Java Program Create a class to store an array of with enough space to store 10 integer values. Using the principle of recursion, implement the following: *getSize : returns the size of the array. *get (i): returns the i-th element of the array. If the element does not exist, it throws a "NoSuchElementException” which is a subclass of Java class RunTimeException. *add (val): inserts value as the last element of the array. If necessary, double the size of the current...

  • 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)

  • write a simple program to receive 6 students’ mid-term grades, store them in array and sort...

    write a simple program to receive 6 students’ mid-term grades, store them in array and sort them in ascending order?

  • Write a Program in C language for: 1. Create a C program to read 7 integers...

    Write a Program in C language for: 1. Create a C program to read 7 integers and store them in an array. Next, the program is to check if the array is symmetric, that is if the first element is equal to the last one, the value of the second one is equal to the value of the last but one, and so on. Since the middle element is not compared with another element, this would not affect the symmetry...

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
ADVERTISEMENT