Answered
Deletion of cell array element performance issue - alternative or solutions?
Keep in mind that deleting an element of a double array means: - Allocating/copying the data (64-bit doubles) to new memory &...

8 years ago | 1

Answered
Performing operation with loop index inside for-loop doesn't work as expected
You don't set the trailing elements of new_hash to spaces on each iteration, or clear new_hash each iteration, so those trailing...

8 years ago | 0

| accepted

Answered
Help with loop error
Maybe move all of the default stuff prior to your if test. E.g., exact = NaN; approx = NaN; abs_error = NaN; ...

8 years ago | 0

Answered
What's the problem?
You can't use 3x in MATLAB ... you have to use 3*x. And you need to use the element-wise .* operator instead of the matrix mult...

8 years ago | 0

Answered
How can I get a user to assign values to a matrix A in the script window?
I don't quit follow what problem you are having. Using your code, with some additional instructions about using square brackets...

8 years ago | 0

| accepted

Answered
pseudorandom sequence without consecutively repeating numbers
This code repeats the randperm( ) groups rather than letting the values be scattered in a more random fashion, but perhaps this ...

8 years ago | 0

Answered
Compute the first 10 Fibonacci numbers
I'm guessing your professor expects you to implement the algorithm that he/she has given you. That is, the next number is the s...

8 years ago | 0

Answered
how do i get the loop to graph properly?
Move this line i = i + 1; outside of the if test. And change this test if i==6 to this instead if k==6 ...

8 years ago | 0

Answered
EMERGENCY Cannot plot "10,000*exp(-10000*t);"
Because you used a comma to define the 10000, and MATLAB sees that comma as a statement separator. MATLAB interprets this line ...

8 years ago | 1

| accepted

Answered
Index exceeds matrix dimensions error
Did you remember to give it a 5-element b vector, or did you inadvertently give it the old 3-element b vector? I tried your cod...

8 years ago | 0

Answered
How do I iteratively fill a large matrix within an anonymous function?
If your attempts at getting all of this logic into an anonymous function are becoming tedious and generating errors, it is time ...

8 years ago | 0

| accepted

Answered
How do I create a new array each time there is an empty matrix in a cell array.
One way: C = your cell array x = [0, find(cellfun(@isempty,C)), numel(C)+1]; n = numel(x)-1; result = cell(1,n); ...

8 years ago | 0

| accepted

Answered
Help with my code?
You are using t as a subscript in these lines, and one of the t values is 0: NO2(t) = (0.5./(1+(0.5)*(k)*t)); NO2_Square...

8 years ago | 0

| accepted

Answered
Who can define a complex matrix in MATLAB? Pleale translate the FORTRAN into Matlab code?
A = bsxfun(@plus,2*(0:20)',(0:10)); B = complex(A); Same resulting matrices as Fortran, except that MATLAB indexing is...

8 years ago | 0

Answered
How to buffer old columns in a matrix when new columns are added
Append reposit this way: histoMat(end+1,1:numel(reposit)) = reposit;

8 years ago | 0

| accepted

Answered
ndims behavior in R2016a
You have likely inadvertently created a variable called "ndims" that is shadowing the MATLAB function of the same name. Clear t...

8 years ago | 1

| accepted

Answered
Question Regarding Division Operation
Using the ./ operator with the dot does element-wise division. Using / without the dot does matrix linear equation solving. So...

8 years ago | 0

Answered
Do I need a file "snoptmex.F90" to run SNOPT in Matlab?
You already know why you are getting the error (because it can't find any m-file or mex-file etc with that name). To fix this, ...

8 years ago | 0

Answered
How can I call MATLAB object's method from C++?
Call it just like a normal function with your Foo object as the input argument. E.g., if you have an object of class Foo at the...

8 years ago | 2

| accepted

Answered
Diagonal Elements of the Square Matrix
Another way: M(1:size(M,1)+1:end) = 1;

8 years ago | 2

Answered
??? Error using ==> mpower Matrix must be square.
You need to use the element-wise operators that have a dot in front of them instead of the matrix operators. So use this instea...

8 years ago | 0

| accepted

Answered
Why is the built-in dot product function somewhat inefficient?
Other than the supposition that dot() needs to be more generic for the multi-dimensional cases it must cover, the "why" is unkno...

8 years ago | 1

| accepted

Answered
Why when comparing the class of a variable, the logical array output size differs?
Use this instead isequal(class(a),'double') or strcmp(class(a),'double') What you are doing with class(a)=='doub...

8 years ago | 1

Answered
I am supposed to write a function that takes three inputs: 1) a Coeff matrix A(nxn square mtx), right side vector b, and approximate soln' vector Xo. The function is then supposed to compute the residual vector r.
To my reading of the assignment, you are making this task more involved than it really is. The assignment states you are given ...

8 years ago | 0

| accepted

Answered
How is this simple code read?
It is the 2nd & 3rd rows and the 2nd & 3rd columns of the matrix mat. The syntax is simply extracting a sub-matrix of the origi...

8 years ago | 1

| accepted

Answered
loop problem with time delay
Hint: You could use tic and toc for this. Start your code with a tic statement. Then you can examine the toc result in a loop...

8 years ago | 0

| accepted

Answered
Loop over randn of vectors
One way, where the 3rd and 4th dimensions of the result are the 20x100 matrix of values for each original vector element. e...

8 years ago | 0

| accepted

Answered
Need help coding a grading system to a data set.
The averages you calculate are in a column vector called Student_Average, but your subsequent code does not even use that variab...

8 years ago | 0

Answered
Average of specific columns from cells in cell array
result = cellfun(@(x)mean(x(:,1)),alldata(4:84));

8 years ago | 1

Answered
Write a function named sindeg that takes a matrix input deg and returns a matrix M that computes the sine of the elements in the input matrix. A second output contains a scalar that is the average of the first.
Assuming your real issue is with 2D matrices (or even 3D arrays etc), and that you need to provide a scalar for that second outp...

8 years ago | 0

| accepted

Load more