when i run my code it give the answers start with Y= ... and give the matrix output divided in column (Columns 1 through 14,Columns 15 through 28 and so on) i want the answer to be a matrix file without Y= or columns divided to parts. how to do this? (my output file is txt file) help needed

댓글 수: 8

Jan
Jan 2014년 10월 19일
편집: Jan 2014년 10월 19일
What exactly is the "matrix file" you are talking of?
Please post your code, because it is much easier to reconsider, what you are doing.
jim
jim 2014년 10월 20일
M = [ 1 1 0 1 0 0 0 0 1 0 0 1 0 0 0 1 1 0 1 1 1 0 1 1 0 1 0 0 0 1 0 0; 1 1 1 0 0 1 1 1 1 1 1 0 0 0 0 1 1 1 1 1 1 0 1 0 1 1 1 1 1 0 1 0; 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 1 1 0 1 0 1 0 0 1 1 1 1 1 1; 1 1 1 0 1 0 0 1 1 1 0 1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1; 1 0 1 0 0 0 0 1 1 1 1 0 0 0 1 0 0 1 0 0 1 0 1 1 1 0 1 0 1 0 0 1; 0 0 0 1 1 0 0 0 1 1 1 1 1 0 0 0 0 1 1 0 1 0 0 0 0 1 1 1 0 0 0 1; 0 1 0 0 0 1 1 1 0 1 0 0 1 0 1 1 1 0 1 0 1 0 0 0 1 1 0 0 0 1 1 0; 1 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 1 0 1 0 1 0 1 1 1 1 1; 1 1 1 1 0 1 0 1 0 0 0 1 1 1 1 1 0 0 1 0 1 0 1 0 1 1 1 1 1 1 1 1; 1 1 1 1 0 1 1 1 0 0 0 0 0 0 1 0 1 1 1 0 1 1 1 1 0 1 0 1 1 1 1 0; 0 0 1 0 1 0 0 0 0 1 0 1 1 0 0 1 0 1 0 1 0 1 0 0 1 0 1 1 0 1 1 1; 1 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 1 1 0 0 0 1 0 0 1 0 1 1 1 1 1 1; 1 1 1 1 0 1 0 1 0 0 0 0 1 0 0 0 1 1 1 0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 1 1 1 1 1 1 0 1 0 1 1 0 1 1 1 0 0 0 1 0 0 0 0 0 1 1 0 1; 0 1 1 1 1 1 0 1 0 1 1 0 0 0 0 1 0 0 1 1 0 0 1 1 0 0 0 0 1 1 1 0; 0 1 1 1 0 0 1 0 0 0 0 1 0 0 0 1 1 1 1 0 1 1 1 1 1 1 1 0 1 1 1 1; 1 0 1 0 0 1 0 1 0 1 1 1 0 1 0 0 1 1 0 0 0 1 0 0 1 1 1 1 1 0 0 1; 1 0 1 1 0 1 0 1 1 0 0 1 1 0 0 0 1 1 1 0 1 1 1 0 1 1 1 1 1 1 0 1; 1 1 0 0 0 0 0 1 0 0 1 1 0 0 1 1 0 0 1 0 0 1 0 1 0 1 1 1 1 0 0 1];
[m,n] = size(M); M2 = [zeros(m,3*ceil(n/3)-n),M]; X = xor(xor(M2(:,1:3:end-2),M2(:,2:3:end-1)),M2(:,3:3:end));
nM = size(M,2);
nX = size(X,2);
n = max(nX,nM)
M = [zeros(m,n-nM),M];
X = [zeros(m,n-nX),X];
diary add6.txt
y = X|M
diary
run this code and you will find the problem with add6.txt
Hikaru
Hikaru 2014년 10월 20일
I'm guessing that you're seeing MATLAB displaying the answer in the command window. The answer is one whole matrix, it's just that the command window has limitation in the amount of characters it can display, which is why you saw (Columns 1 through 14,Columns 15 through 28 and so on). To view the matrix, simply click on the variable Y in your workspace. Just a guess, not sure if I understood your question right.
jim
jim 2014년 10월 20일
편집: jim 2014년 10월 20일
yes, Y gave the true matrix. but why txt file didn't give the right answer as Y in workspace? i try to save on doc but it gave the same answer as txt format. is there any format i can use to give the right answer?
Hikaru
Hikaru 2014년 10월 20일
편집: Hikaru 2014년 10월 20일
You used function diary to create the text file, but diary is really just whatever that is displayed in your command window (not like in the workspace). If you want the output Y in a text file, use fprinf.
fileID = fopen('output.txt','w')
fprintf(fileID,'%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\r\n',y);
fclose(fileID);
Or if you want the columns to be together, just remove the spaces between %d.
jim
jim 2014년 10월 20일
it works fine, but i had to change y to y' to get the right answer, but also the matrix came mirrored, bit 32 came in bit1 and bit 31 came in bit2 position and bit1 came in bit32, and so on. like instead of 11001 it came as 10011 how to make it right?
I don't really know why, but you are right, y' gives the correct output. And I tested it using your matrix M, I didn't see the mirrored bit.. my output is attached, is it not the same as y?
fileID = fopen('output.txt','w')
fprintf(fileID,'%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\r\n',y');
fclose(fileID);
jim
jim 2014년 10월 20일
yes its right now,,, i try it again and it runs without mirror..maybe i was mistaking before. thanks a lot man ... i try to vote for you but i couldn't find the link thanks

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

 채택된 답변

Jan
Jan 2014년 10월 19일
편집: Jan 2014년 10월 20일

0 개 추천

What about using fprintf to write to the command window?
[EDITED]
What about:
fmt = [repmat('%d ', 1, 31), '%d\r\n'];
fileID = fopen('output.txt','w')
fprintf(fileID, fmt, flipud(y'));
fclose(fileID);

추가 답변 (1개)

MatlabFan
MatlabFan 2014년 10월 19일

0 개 추천

I suggest that you rephrase your question, and be more specific about what exactly it is that you are trying to achieve. I don't have any idea of what you need help on, because your question is not well posed. Please, pose your question in a way that gives clear details as to what you want to accomplish; and I'm sure you will get very satisfactory answers, and in a quick turnaround time too.

댓글 수: 2

jim
jim 2014년 10월 19일
i added two matrix (50*30) and the result (Y= X+Z) was divided in column (Columns 1 through 14,Columns 15 through 28 and so on) started with Y= . I want the result to be pure matrix.without Y= i want the column to be all together without division. 1111000111000110011100101001; 0001100010011110011011100100;
Jan
Jan 2014년 10월 19일
The output is a pure matrix.
I cannot understand, how tzhe addition of two [50 x 30] matrices can create a [2 x 28] matrix.

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

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

jim
2014년 10월 19일

댓글:

jim
2014년 10월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by