Arithmetic problem with for loop

์กฐํšŒ ์ˆ˜: 1 (์ตœ๊ทผ 30์ผ)
Mustafa Uysal
Mustafa Uysal 2019๋…„ 5์›” 22์ผ
๋Œ“๊ธ€: Mustafa Uysal 2019๋…„ 5์›” 23์ผ
Hi, i am new with MATLAB.
I would like to use this formula in for loop: โ„“?=taper1*โ„“?โˆ’1
There is no error message but i can't see a proper value on output. (i control my values with calculator programs) (i checked my variables. and confirmed that they are true before this loop).
And my second problem is i don't know how to add new line with every increment.
Here is my try:
l= (1:N); //creating and empty array
l(1)=((3*(10^8))/(2*f1)); //formula
for i = 2:N
l(i) = taper1 * l(i - 1);
set(handles.popupmenu3,'String',l(i) );
end
i tried to add new line with this but didn't work
set(handles.popupmenu3,'String',l(i) \n );
  ๋Œ“๊ธ€ ์ˆ˜: 1
Rik
Rik 2019๋…„ 5์›” 22์ผ
Most of what you have shown here is not valid Matlab syntax. It seems like you lack the basics of Matlab. It is really useful to learn the basics before attempting more complicated things. This even holds true for a relatively simple language as Matlab.
This is one of many tutorials you could try.

๋Œ“๊ธ€์„ ๋‹ฌ๋ ค๋ฉด ๋กœ๊ทธ์ธํ•˜์‹ญ์‹œ์˜ค.

์ฑ„ํƒ๋œ ๋‹ต๋ณ€

Walter Roberson
Walter Roberson 2019๋…„ 5์›” 22์ผ
ํŽธ์ง‘: Walter Roberson 2019๋…„ 5์›” 23์ผ
l = zeros(1,N); %creating and empty array
l(1) = ((3*(10^8))/(2*f1)); %formula
for i = 2:N
l(i) = taper1 * l(i - 1);
handles.popupmenu3.String{end+1} = num2str( l(i) );
drawnow();
end
updating the popup string one by one is inefficient: it would be better to do all of the calculations first and then update at the end.
Note: you could also calculate
l = ((3*(10^8))/(2*f1)) .* taper1.^(0:N-1);
with no loop required.
  ๋Œ“๊ธ€ ์ˆ˜: 7
Rik
Rik 2019๋…„ 5์›” 23์ผ
So like this?
sprintf('l(%d)= %.1f',i,l(i))
Otherwise, try searching the documentation for a solution. Matlab has excellent documentation with many examples.
Mustafa Uysal
Mustafa Uysal 2019๋…„ 5์›” 23์ผ
It works thank you.

๋Œ“๊ธ€์„ ๋‹ฌ๋ ค๋ฉด ๋กœ๊ทธ์ธํ•˜์‹ญ์‹œ์˜ค.

์ถ”๊ฐ€ ๋‹ต๋ณ€ (0๊ฐœ)

์นดํ…Œ๊ณ ๋ฆฌ

Help Center ๋ฐ File Exchange์—์„œ Loops and Conditional Statements์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์•„๋ณด๊ธฐ

ํƒœ๊ทธ

Community Treasure Hunt

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

Start Hunting!

Translated by