フィルターのクリア

Can any one help me in adding new line space to the result. Thanks in advance

4 ビュー (過去 30 日間)
RajyaLakshmi
RajyaLakshmi 2014 年 2 月 5 日
コメント済み: Walter Roberson 2014 年 2 月 6 日
fid=fopen('largeadd.m','r');
result=' ';
while(feof(fid)~=1)
temp=char(fread(fid));
for i=1:max(size(temp))
if(~isspace(temp(i,1)))
result=strcat(result,char(temp(i,1)));
disp(isspace(temp(i,1)));
else
result=strcat(result,'\n');
end
end
end
end
disp(result);

回答 (2 件)

Walter Roberson
Walter Roberson 2014 年 2 月 5 日
result = strcat(result,sprintf('\n'));
  2 件のコメント
RajyaLakshmi
RajyaLakshmi 2014 年 2 月 6 日
編集済み: Walter Roberson 2014 年 2 月 6 日
Thank you sir.
but my requirement is not obtained on using this statement.
The output obtained is:
%Additionoflongnumbersclc;num1=input('Enteravalue','s');num2=input('Enterbvalue','s');asize=max(size(num1));disp(size(num1));fori=1:asizea(1,i)=str2num(num1(1,i));disp(a(1,i));b(1,i)=str2num(num2(1,i));disp(b(1,i));end%disp(a);fori=1:asizec(1,i)=a(1,i)+b(1,i);disp(c(1,i));endfori=2:asizeif(c(1,i)>=10&&i>=2)c(1,i)=c(1,i)-10;c(1,i-1)=c(1,i-1)+1;endendresult='';if(c(1,1)>=10)c(1,1)=c(1,1)-10;result=strcat(result,num2str(1));endfori=1:asizeresult=strcat(result,num2str(c(1,i)));enddisp(result);
But the Expected is:
%Addition of long numbers
clc;
num1=input('Enter a value','s');
num2=input('Enter b value','s');
asize=max(size(num1));
disp(size(num1));
for i=1:asize
a(1,i)=str2num(num1(1,i));
disp(a(1,i));
b(1,i)=str2num(num2(1,i));
disp(b(1,i));
end
%disp(a);
for i=1:asize
c(1,i)=a(1,i)+b(1,i);
disp(c(1,i));
end
for i=2:asize
if(c(1,i)>=10&&i>=2)
c(1,i)=c(1,i)-10;
c(1,i-1)=c(1,i-1)+1;
end
end
result='';
if(c(1,1)>=10)
c(1,1)=c(1,1)-10;
result=strcat(result,num2str(1));
end
for i=1:asize
result=strcat(result,num2str(c(1,i)));
end
disp(result);
Any other results or answers welcome thanks in advance
Walter Roberson
Walter Roberson 2014 年 2 月 6 日
fread(fid) reads the entire file.
max(size(temp)) can be replaced by length(temp)
I have to wonder why you are doing all of this. Why not just read the file and then use
temp(isspace(temp)) = sprintf('\n');

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


Image Analyst
Image Analyst 2014 年 2 月 6 日
Why do all that? Just use fgetl() or fgets().
thisLine = fgets(fid);
lineWithExtraLineFeed = sprintf('%s\n', thisLine);
  2 件のコメント
Image Analyst
Image Analyst 2014 年 2 月 6 日
By the way, you forgot to call fclose(fid).
Walter Roberson
Walter Roberson 2014 年 2 月 6 日
The user's code changes every whitespace character to \n

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

カテゴリ

Help Center および File ExchangeOther Formats についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by