Why do I get "Error using matlab.gra​phics.prim​itive.Text​/set The property name 'num2str(k)' is not a valid MATLAB identifier" in the 'title' line of my coding?

11 Ansichten (letzte 30 Tage)
for k = 1:2:19
x = x + A*cos((pi/2)-k*2*pi*fc*t)/k;
y((k+1)/2,:) = x;
axis([0 0.05 -4 4]);
xlabel('Time (s)');
ylabel('Amplitude (V)');
title('Sum of ',num2str(k), 'th odd harmonics');
grid on;
end

Antworten (1)

Voss
Voss am 13 Dez. 2021
Calling title like that sends three input arguments to title. This is not what you intend to do. You need to concatenate those three strings first, then send the result to title. Like this:
title(['Sum of ',num2str(k), 'th odd harmonics']);

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by