How to save each and every output of if statement and else statement used in for loop??? How to access the saved values for further assisstance

3 ビュー (過去 30 日間)
Ne=16;
for ii = 1:Ne
enc_x(ii+1) = r*enc_x(ii)*(1 - enc_x(ii));
enc_y(ii+1) = r*enc_y(ii)*(1 - enc_y(ii));
if (enc_x(ii)>enc_y(ii))
fprintf('Iterrations No %i ',ii);
fprintf('%d',0);
fprintf('\n');
else
fprintf('Iterrations No %i ',ii);
fprintf('%d',1);
fprintf('\n');
end;
end

回答 (2 件)

KSSV
KSSV 2018 年 11 月 28 日
iwant = zeros(1,10) ;
for i = 1:10
x = rand ;
if x<0.5
iwant(i) = x-0.5 ;
else
iwant(i) = x+0.5 ;
end
end
  2 件のコメント
KALYANAPU  SRINIVAS
KALYANAPU SRINIVAS 2018 年 11 月 28 日
i want to save each iteration output but your code is outputs last saved result
KSSV
KSSV 2018 年 11 月 28 日
It saves for all the loop values..check it.

サインインしてコメントする。


KALYANAPU  SRINIVAS
KALYANAPU SRINIVAS 2018 年 12 月 13 日
Thank you for the answer.
I want to save the iwant output to .txt file. But When I tried and opened the test.txt file it is displaying the last loop output. I want to save each iteration output in text.txt file one after the another like
11
32
55
77
.......
I tried with 'wt' mode in fopen but not succeded. I tried using \n also but no use. help me in this regard

カテゴリ

Help Center および File ExchangeLarge Files and Big Data についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by