Answered
Homework help.(User defined functions )
Hint: See these functions: doc size doc isequal doc error

6 years ago | 0

| accepted

Answered
trouble understanding for loops
The first problem is getting the input from the user. This assigns a char string to pv: pv=('What was your original mortgage v...

6 years ago | 0

Answered
OR statement in a while Loop
Change to AND: while ((playerhp > 0) && (enemyhp > 0)) I.e., you only do the while loop when both hp are positive. It eit...

6 years ago | 0

| accepted

Answered
Fastest way to find the row number containing the most amount of black pixels in a gray-scale image?
[~,row_blackPix] = max(sum(image <= 20,2))

6 years ago | 1

| accepted

Answered
Varying step size for RK Method?
The only variable that depends on a new n is h, so only recalculate h and then run your loop as is. Although if you want to make...

6 years ago | 0

| accepted

Answered
conversion from base 13 to IEEE 754
For the base 13 conversions: doc dec2base doc base2dec https://www.mathworks.com/help/matlab/ref/dec2base.html https://www.m...

6 years ago | 0

Answered
Whats wrong with my code? Taylor series Approx with error
You probably just need an absolute value error = abs((true-s)/true)*100; %Percent Error Formula That being said, true and erro...

6 years ago | 0

Answered
Functions and For Loops For Polynomials
Some guidance: 1) The sum=0 part needs to be moved outside the loop, prior to the loop starting. The way you have it the sum re...

6 years ago | 1

| accepted

Answered
How can I randomly select a subset of logicals?
T = your logical trials vector n = 20; % number of trials to keep f = find(T); % find the location of the 1's f = f(randperm(...

6 years ago | 1

| accepted

Answered
Custom help information on structure fields
See this discussion: https://www.mathworks.com/matlabcentral/answers/480829-what-is-the-best-way-to-insure-that-all-of-my-funct...

6 years ago | 2

| accepted

Answered
Error using * Matrix dimensions must agree.
Change this piv=A(i:i); to this piv=A(i,i); And change this fac=A(j:i)./piv; to this fac=A(j,i)./piv;

6 years ago | 0

Answered
how to print multiple variables with strings in between ?
You could use fprintf. E.g. >> a = 5; >> b = 7; >> fprintf("Variable a equals: %g\n",a); Variable a equals: 5 >> fprintf("V...

6 years ago | 2

| accepted

Answered
Swapping last matrix columns
From your description, I don't see how your code works for anything other that inputs having two columns. I would guess that thi...

6 years ago | 1

| accepted

Answered
C/Fortran callback to MATLAB
Maybe this can give you the framework you need. I have made some assumptions about how things are connected. You pass in a cha...

6 years ago | 0

| accepted

Answered
Common numbers between arrays
You could write some code using the intersect( ) function for this. E.g., the first result >> A = {[1,2,3], [3 4 5 6], [3 7 8 ...

6 years ago | 1

| accepted

Answered
How could I solve the problem of if statement for even and odd values?
mod(N,1) does not determine if a number is even or odd. You would want something like mod(N,2)==0 or mod(N,2)~=0. E.g., mod(Z...

6 years ago | 0

| accepted

Answered
Parse/Syntax Error
lamda**2 is Fortran. I presume you want lamda^2 instead

6 years ago | 0

Answered
How can plot every n-th element in a vector AND the last element?
If you don't care about possibly overplotting that last point twice, then simply n = 10; result = [p(n:n:end) p(end)]; If you...

6 years ago | 0

| accepted

Answered
element-wise exponential of matrix returns all 1s
Your calculations are sensitive to the input numbers. E.g., >> format longg >> thetas(1) ans = 12566.3706143592 >...

6 years ago | 0

Answered
Subscript indicies must either be real positive integers or logicals
... rho((4/3) ... should be ... rho*((4/3) ...

6 years ago | 0

Answered
How do I create a for loop in MATLAB for this?
If you want to use the overall min and max, then just use A(:) for the calculations. E.g., B = (A-min(A(:)))/[max(A(:))-min(A(:...

6 years ago | 1

Answered
How to multiply each numeric element in a cell array with a given number
Do you mean something like this? >> C = {'text'; 1; 1:2; 1:3} C = 4×1 cell array {'text' } {[ 1]} {...

6 years ago | 0

Answered
how do I locate a question I asked a few days ago?
If you are already on the Answers page, just click on the "My MATLAB Answers" dtop-down menu at the top and select "My Questions...

6 years ago | 0

Answered
Combining results of a 3D array
Is any(S,3) what you want?

6 years ago | 0

| accepted

Answered
Help with ODE45
G1 and G2 are symbolic expressions. ode45( ) is a numeric solver. You will need to turn G1 and G2 into actual non-symbolic cod...

6 years ago | 0

| accepted

Answered
Proof that sum of all positive integers is -1/12
This has nothing to do with MATLAB and numerical sums. You can pretty much get any answer you want by manipulating divergent se...

6 years ago | 3

| accepted

Answered
Using ode45 to solve odes from a matrix
F = [-f1 f1 0 0; 0 -f2 f2 0; 0 0 -f3 f3; v 0 0 -v].'; f = @(t,y) F * y;

6 years ago | 1

| accepted

Answered
Differentiating within a for loop
I assume by "three times" what was meant was diffferentiate the results iteratively three times, not differentiate the original ...

6 years ago | 0

Answered
Coding fibonacci without using fibonacci matlab code
Hint: The fprintf( ) function will automatically wrap around if you have too many variables than the format string allows for. E...

6 years ago | 0

Answered
How do I fill a matrix of 1s and 0s with sequential numbers
nnza = nnz(A); nnzb = nnz(B); At = A'; Bt = B'; At(logical(At)) = 1:nnza; Bt(logical(Bt)) = (nnza+1):(nnza+nnzb); Aresult ...

6 years ago | 0

| accepted

Load more