Azzera filtri
Azzera filtri

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

2 visualizzazioni (ultimi 30 giorni)
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 Commenti
Image Analyst
Image Analyst il 5 Set 2015
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 il 6 Set 2015
I just tried Image Analyst's code in R2014a on OS-X, and the result looks fine to me with highestValue = 9.

Accedi per commentare.

Risposte (2)

Image Analyst
Image Analyst il 6 Set 2015
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 Commento
Image Analyst
Image Analyst il 7 Set 2015
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?

Accedi per commentare.


Walter Roberson
Walter Roberson il 7 Set 2015
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);

Categorie

Scopri di più su Linear Model Identification in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by