필터 지우기
필터 지우기

how to save binary matrix with dimension (418 x 627) in to text file in matlab

조회 수: 2 (최근 30일)
how to save binary matrix with dimension (418 x 627) in to text file in matlab.. i tried with dlmwrite, save, fwrite.. with these i did not get..
can any one help me
below is program:
clc;
clear all;
close all;
d=[3,7,13,21,4,10,18,6,14,8,5,33,75,131,28,70,126,42,98,56,9,53,119,207,44,110, 198, 66, 154, 88];
length(d);
s1=[0, 3, 7, 13, 21];
s2=[0, 5, 33, 75, 131];
s3=[0, 9, 53, 119, 207];
maxvalue= max([s1(:);s2(:);s3(:)]);
l=209;
obtained=l-d;
s1=zeros(1,209);
s1([1,4,8,14,22])=1;
length(s1);
s2=zeros(1,209);
s2([1,6,34,76,132])=1;;
length(s2);
s3=zeros(1,209);
s3([1,10,54,120,208])=1;
length(s3);
s1sm=toeplitz(s1([1,end:-1:2]),s1);
s2sm=toeplitz(s2([1,end:-1:2]),s2);
s3sm=toeplitz(s3([1,end:-1:2]),s3);
H=[s1sm s2sm s3sm];
f=transpose(H);
x=gf(s3sm);
q=rank(s3sm);
a=inv(x);
b=eye(209);
c=a*s1sm;
e=a*s2sm;
G=[b zeros(209) c';zeros(209) b e'];
G*H';
i want to save G matrix in text document.. how to do?
  댓글 수: 3
Image Analyst
Image Analyst 2015년 9월 5일
For what it's worth,
highestValue = 9;
binaryMatrix = randi([0,highestValue], 418, 627);
csvwrite('binaryMatrix.csv', binaryMatrix);
if highestValue = 10 or more, it's fine (normal text file), but it if's 9 or less, it's gibberish. Also tried with txt extension. I don't know why. I also tried creating only 0s and 1s and casting to logical - same problem. Only works if > 10 for some reason.
Walter Roberson
Walter Roberson 2015년 9월 6일
I just tried Image Analyst's code in R2014a on OS-X, and the result looks fine to me with highestValue = 9.

댓글을 달려면 로그인하십시오.

답변 (2개)

Image Analyst
Image Analyst 2015년 9월 6일
Here's what it looks like if you use 10 or higher:
Here's what it looks like if you bring it up if you use 9 or less:
Actually I determined that it's just some kind of notepad or wordpad quirk, because if you add the "type" line after the code:
highestValue = 9;
binaryMatrix = randi([0,highestValue], 41, 62);
csvwrite('binaryMatrix.csv', binaryMatrix);
type 'binaryMatrix.csv'
it looks fine:
So it depends on how you verified what you got. How did you determine that it did not work?
  댓글 수: 1
Image Analyst
Image Analyst 2015년 9월 7일
Satishkumar's comment moved here:
clc;
clear all;
close all;
d=[3,7,13,21,4,10,18,6,14,8,5,33,75,131,28,70,126,42,98,56,9,53,119,207,44,110, 198, 66, 154, 88];
length(d);
s1=[0, 3, 7, 13, 21];
s2=[0, 5, 33, 75, 131];
s3=[0, 9, 53, 119, 207];
maxvalue= max([s1(:);s2(:);s3(:)]);
l=209;
obtained=l-d;
s1=zeros(1,209);
s1([1,4,8,14,22])=1;
length(s1);
s2=zeros(1,209);
s2([1,6,34,76,132])=1;;
length(s2);
s3=zeros(1,209);
s3([1,10,54,120,208])=1;
length(s3);
s1sm=toeplitz(s1([1,end:-1:2]),s1);
s2sm=toeplitz(s2([1,end:-1:2]),s2);
s3sm=toeplitz(s3([1,end:-1:2]),s3);
H=[s1sm s2sm s3sm];
f=transpose(H);
x=gf(s3sm);
q=rank(s3sm);
a=inv(x);
b=eye(209);
c=a*s1sm;
e=a*s2sm;
G=[b zeros(209) c';zeros(209) b e'];
G*H';
how to save G matrix in text doc?

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2015년 9월 7일
This code assumes that G is 2 dimensional
[Grows, Gcols] = size(G);
fmt = [repmat('%.16g ', 1, Gcols-1), '%.16g\n'];
[fid, message] = fopen('TheOutputFile.txt', 'wt');
if fid < 0
error('Could not open output file because: "%s"', message);
end
fprintf(fid, fmt, G');
fclose(fid);

카테고리

Help CenterFile Exchange에서 Linear Model Identification에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by