Getting an error For colon operator with char operands, first and last operands must be char.

Im getting an error called "Error using : For colon operator with char operands, first and last operands must be char." I have the code that im trying to use for reference. I asked my professor about it and he doesnt have a solution for me and suggested me to talk to someone that might here.

3 Comments

Show us the code which threw error. With out showing code how you expect us to help you?
The error message is easy to reproduce:
1:'a':100
Error using :
For colon operator with char operands, first and last operands must be char.
But because you do not explain anything about your code, we have no idea what you are trying to achieve or why.
clear
clc
k=.0004
Re=2.*10.^6
F=@(f) -.86*ln((k./3.7)+(2.51./Re.*sqrt(f)))-sqrt(1/f)
j=('Input number of crossings =')
for i=1:j
f=input('the approxmate f where F is zero =')
fzero(F,f)
end
This is the code i have that results in the error

Sign in to comment.

Answers (1)

This line
j=('Input number of crossings =')
should be
j = input('number of crossings =')

3 Comments

why doesnt it like this? my professor uses it and when i load his codes it works fine
clear
clc
clf
figure(1)
fplot(@(x) x.*exp(-x)-0.2,[0 8])
hold
fplot(@(y) y-y)
grid
F=@(x) x.*exp(-x)-0.2
n=input('the number of zero crossings =')
for i=1:n
x=input('the approxmate x where F is zero =')
fzero(F,x)
end
disp(' ')
disp(' ')
disp('PRESS ENTER TO CONTINUE')
pause
when i load this from a link and load it from matlab it runs fine
OHHHHH i feel so dumb. thanks for the help. stupid simple mistakes changes everything
@Joshua Meyer: sometimes a second pair of eyes is handy :) Please remember to accept my answer!

Sign in to comment.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Release

R2021b

Asked:

on 16 Nov 2021

Edited:

on 17 Nov 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!