Question

In: Computer Science

Matlab work. Pleaae dont copy from any source. Write a function that will accept a structure...

Matlab work. Pleaae dont copy from any source.

Write a function that will accept a structure as an argument and return two cell arrays containing the names of the fields of that structure and the data types of each field. Be sure to check that the input argument is a structure, and generate an error message if it is not.

Solutions

Expert Solution

A structure array is a data type that groups related data using data containers called fields. Each field can contain any type of data. Access data in a field using dot notation of the form structName.fieldName.

Creation

When you have data to put into a new structure, create the structure using dot notation to name its fields one at a time:

s.a = 1;
s.b = {'A','B','C'}
s = struct with fields:
    a: 1
    b: {'A'  'B'  'C'}

You also can create a structure array using the struct function, described below. You can specify many fields simultaneously, or create a nonscalar structure array.

Syntax

s = struct

s = struct(field,value)

s = struct(field1,value1,...,fieldN,valueN)

s = struct([])

s = struct(obj)

Description

s = struct creates a scalar (1-by-1) structure with no fields.

example

s = struct(field,value) creates a structure array with the specified field and value. The value input argument can be any data type, such as a numeric, logical, character, or cell array.

  • If value is not a cell array, or if value is a scalar cell array, then s is a scalar structure. For instance, s = struct('a',[1 2 3]) creates a 1-by-1 structure, where s.a = [1 2 3].

  • If value is a nonscalar cell array, then s is a structure array with the same dimensions as value. Each element of s contains the corresponding element of value. For example, s = struct('x',{'a','b'}) returns s(1).x = 'a' and s(2).x = 'b'.

  • If value is an empty cell array {}, then s is an empty (0-by-0) structure.


Related Solutions

Write a function using MATLAB that will accept a structure as an argument and return two...
Write a function using MATLAB that will accept a structure as an argument and return two cell arrays containing the names of the fields of that structure and the data types of each field. Be sure to check that the input argument is a structure, and generate an error message if it is not.
Please don’t copy from the same site and No copy from any source. The work should...
Please don’t copy from the same site and No copy from any source. The work should be your own words and answer. And please don’t answers be handwriting Discuss an example of an expert system in any filed and explain the importance of creating this system.
It is a simple discussion please dont copy from any website, Ii need to be at...
It is a simple discussion please dont copy from any website, Ii need to be at least 3 paragraph. thanks Discussion "The Women's Kingdom" Please watch "The Women's Kingdom" which is a video about a matrilineal group in China and this video will give you an insight into a very different marriage pattern that most students are familiar with. After you have watched the video, research and post on a marriage pattern of a particular culture that is different from...
Using Matlab do the following Write a program that will accept a number from the user...
Using Matlab do the following Write a program that will accept a number from the user and: Check if the number between 50 and 100both inclusive. If yes print a comment. If not print a warning. The program sums the inserted values This process continues until the user inserts the number 999 . At this point the program quits and prints the result of (2)
A. Write a function in MATLAB called findTranspose that takes in as input any matrix or...
A. Write a function in MATLAB called findTranspose that takes in as input any matrix or any vector and simply returns back the transpose of that input. You can always verify your answer by using the inbuilt transpose function in MATLAB, however, you cannot use the transpose function directly when writing your code. Here is the starter code that we are providing to help you get started %x is the input vector or matrix. You can find the %size that...
Using MatLab Write a program which will: a. Accept two numbers from the user m and...
Using MatLab Write a program which will: a. Accept two numbers from the user m and n b. Define an array with the dimensions a(n,m) and fill it with random numbers in the range of -100 to 100 inclusive. c. Accept from the user two row numbers. Multiply the two rows (element by element) and find the sum. Print the result. d. Accept from the user two column numbers. Add the two columns (element by element) and find the sum....
Matlab You will write a function to calculate the determinant of a matrix. It should work...
Matlab You will write a function to calculate the determinant of a matrix. It should work for any size matrix. Remember that the determinant can be calculated by multiplying the diagonal elements of an upper right triangular matrix. Your function will take a matrix passed to it and put it in upper right triangular form. You will work down the diagonal beginning at row 1 column 1, then row 2 column 2, etc. Note that the row and column numbers...
Plagirism is prohibited please dont copy from internet. Write individual report on the challenges and opportunities...
Plagirism is prohibited please dont copy from internet. Write individual report on the challenges and opportunities of doing business in different countries and relate culture to the management of an organization.
I need a user developed "eig" function (copy of already developed eig function from matlab) without...
I need a user developed "eig" function (copy of already developed eig function from matlab) without using too much higher order math (matrix multiplication, cross and dot products and elementary row operations are all kosher) to do so, in matlab. without the use of a toolbox. if anyone can help me it would be appreciated.
PLEASE DONT COPY FROM INTERNET PLAGIRISM IS PROHIBITED WRITE 2000 WORDS ON THE TOPIC. QUESTION 01:...
PLEASE DONT COPY FROM INTERNET PLAGIRISM IS PROHIBITED WRITE 2000 WORDS ON THE TOPIC. QUESTION 01: World Rankings of UAE and its Implications (REQUIRE 2000 WORDS) 1. Introduction of the topic 2. Review of literature 3. Data, methodology 4. Analysis & Findings of the study 5. Conclusion 6. Reference
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT