Question

Write lines of code that generate each of the following array-related errors: ??? Error: Unbalanced or...

Write lines of code that generate each of the following array-related errors:
??? Error: Unbalanced or unexpected parenthesis or bracket.
??? Attempted to access A(-1); index must be a positive integer
or logical.
??? Error using ==> horzcat CAT arguments dimensions are not
consistent.
??? Error using ==> vertcat CAT arguments dimensions are not
consistent.
??? In an assignment A(I) = B, the number of elements in B and
I must be the same.
??? Error using ==> plus Matrix dimensions must agree.
??? Attempted to access A(4); index out of bounds because
numel(A)=3.

Homework Answers

Answer #1

1). ??? Error: Unbalanced or unexpected parenthesis or bracket

When the number of left paranthesis and right parenthesis does not match then this error occurs.

A =[1 2 3 4];

Array indices must be positive integers or logical values.

A(1:

Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.

2). ??? Attempted to access A(-1); index must be a positive integer
or logical.

There are no negative indexing. So we will get error when we try to access using negative indexes

A =[1 2 3 4 5 6];

A(-1)

Array indices must be positive integers or logical values.

3). ??? Error using ==> horzcat CAT arguments dimensions are not
consistent.

When number of rows in A and B are not equal and we use horzcat() then we will get this error.

A = [1 2 3 ; 4 5 6];

B = [10 11 12; 12 13 14;14 15 16];

horzcat(A,B)

Error using horzcat
Dimensions of arrays being concatenated are not consistent.

4). ??? Error using ==> vertcat CAT arguments dimensions are not
consistent.

When number of columns in A and B are not equal and if we use vertcat() then we will get this error.

A = [1 2 3 ; 4 5 6];

B = [10 11 ; 12 13 ;14 15 ];

vertcat(A,B)

Error using vertcat
Dimensions of arrays being concatenated are not consistent.

5). ??? In an assignment A(I) = B, the number of elements in B and
I must be the same.

When we assign more than one elements to a single position then we will get this error.

In the following example we are assigning a vector B to the first position of A. SO it gives error.

A = [1 2 3 4 5 6];

B = [7 8 9 10];

A(1) = B

Unable to perform assignment because the left and right sides have a different number of elements.

6). ??? Attempted to access A(4); index out of bounds because
numel(A)=3
.

When we are trying to access an index which is not present we will get this error.

A = [1 2 3];

A(4)

Index exceeds the number of array elements (3).

Know the answer?
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
Similar Questions
Note: Do not use classes or any variables of type string to complete this assignment Write...
Note: Do not use classes or any variables of type string to complete this assignment Write a program that reads in a sequence of characters entered by the user and terminated by a period ('.'). Your program should allow the user to enter multiple lines of input by pressing the enter key at the end of each line. The program should print out a frequency table, sorted in decreasing order by number of occurences, listing each letter that ocurred along...
Using the following code perform ALL of the tasks below in C++: ------------------------------------------------------------------------------------------------------------------------------------------- Implementation: Overload input...
Using the following code perform ALL of the tasks below in C++: ------------------------------------------------------------------------------------------------------------------------------------------- Implementation: Overload input operator>> a bigint in the following manner: Read in any number of digits [0-9] until a semi colon ";" is encountered. The number may span over multiple lines. You can assume the input is valid. Overload the operator+ so that it adds two bigint together. Overload the subscript operator[]. It should return the i-th digit, where i is the 10^i position. So the first...
STRICT DOWNVOTE IF NOT DONE FULLY, WILL REPORT ALSO IF COPY PASTED OR MODIFIED ANSWER Develop...
STRICT DOWNVOTE IF NOT DONE FULLY, WILL REPORT ALSO IF COPY PASTED OR MODIFIED ANSWER Develop a class, using templates, to provide functionality for a set of recursive functions. The functions specified as recursive must be written recursively (not iterativly). The UML class specifications are provided below. A main will be provided. Additionally, a make file will need to be developed and submitted. ● Recursion Set Class The recursion set template class will implement the template functions. recursionSet -length: int...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT