I have a matix, A, of 100x200 zeros. I will be taking data from an oscilloscope that will continually be written to a matrix, B, 1X1. I want to write a loop that inputs B into the spot 1,1 of A. Then after the oscilloscope has taken new data and rewritten B, input it into spot 1,2. When the first line is complete I want the data to go into 2,1 and so on till A is full up. How might I write this loop?

댓글 수: 1

John D'Errico
John D'Errico 2017년 1월 12일
편집: John D'Errico 2017년 1월 12일
Why pray tell, do you want to write data into a matrix along those diagonals? Where does the 4th element go?

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

 채택된 답변

John Chilleri
John Chilleri 2017년 1월 12일
편집: John Chilleri 2017년 1월 12일

0 개 추천

Hello,
You can fill in your matrix by rows with this:
for i = 1:100
for j = 1:200
% Acquire your B
A(i,j) = B;
end
end
Hope this helps!

댓글 수: 3

Jacob Hollebon
Jacob Hollebon 2017년 1월 13일
Very helpful, thanks!
When I try and run this now, I get the error 'Attempted to access A(0,0); index must be a positive integer or logical.'
I have tried formatting A as
A = zeros (100,200,'double')
as B is variable type double. But still get the same error.
John Chilleri
John Chilleri 2017년 1월 13일
Your loop goes from i=1:100 and j=1:200 correct? Not 0:100 and 0:200? This error occurs when you try to access A(0,0) which does not exist.

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

추가 답변 (0개)

질문:

2017년 1월 12일

댓글:

2017년 1월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by