Replace value in matrix

Hi,
I'm looking at the orientation of lines generating using linear regression.
I create a matrix that increases after each loop, generating a new columns with a number of data higher than the previous columns (because there is more lines).
My problem is that in the end my matrix is [24*17], however the data in the first colum are only 3 values, and the rest (19 cells) filled with zeros.
I'd like to analyse the matrix, but i can'tget rid of the "filling-zeros".
Does anyone have an idea?
Thanks
N.

댓글 수: 3

Nicolas
Nicolas 2011년 3월 14일
The 17th colum is 24 values, the 1st one : 3 values and 21 zeros, the 2nd: 5 values and 19 zeros; the 3rd: 6 values and 18 zeros... and so on
Walter Roberson
Walter Roberson 2011년 3월 14일
Is the matrix the _result_ of linear regression, or is it input being fed into linear regression ? If it is input to linear regression, what would you intend it to mean to the formula -- that the corresponding components are zero ?
Nicolas
Nicolas 2011년 3월 16일
it is the results of linear regression.

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

 채택된 답변

Oleg Komarov
Oleg Komarov 2011년 3월 16일

0 개 추천

You can obtain:
A = [0 0 143 143 152
0 0 0 0 151
0 0 0 0 143];
regexprep(evalc('A'), '0', ' ')
A =
143 143 152
151
143
But it's a non tractable string array, i.e. what you're trying to do is meaningful only for visualization purposes and privates A of any computational use.
Oleg

댓글 수: 5

Nicolas
Nicolas 2011년 3월 16일
Oh, yes that's what I should have say since the beginning ! it's to plot the data!
thanks
Walter Roberson
Walter Roberson 2011년 3월 16일
But you _did_ say in the beginning: you said "I'd like to analyse the matrix". Not analyze the form of a _printout_ of the matrix. Thus, putting in spaces does not meet your requirements as stated. Did your requirements change along the way?
Oleg Komarov
Oleg Komarov 2011년 3월 16일
To plot data, i.e. to represent it by means of graphs, follow Paulo's indications.
To display/visualize the matrix (as Walter suggests, to analyze its printout) use the approach I suggested.
Just keep in mind terminology for future questions.
Nicolas
Nicolas 2011년 3월 16일
regexprep(A, '0', ' ')
Nicolas
Nicolas 2011년 3월 16일
Sorry, my explanations are a bit confusing.
My first idea was to analyse the matrix, by "analysing" i meant plotting the direction values of each column in a compass plot (all the data, then by sector of 10 degrees) to see preferential orientations. The problem that you helped me to solve was to get rid of the "filling-zeros", because my matrix is growing in each loop both row and column.
I hope it is a bit more clear for you.

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

추가 답변 (2개)

Paulo Silva
Paulo Silva 2011년 3월 14일

0 개 추천

Two options:
1-ignore first column
mat(:,2:end)
2-replace the zeros on the first column
mat(mat(:,1)==0)=inf %replace zeros with inf
you can choose other things besides inf, maybe NaN or a really small value like eps
3-extra option, replace all zeros
mat(mat==0)=inf %again you can choose the value to replace the zeros
Nicolas
Nicolas 2011년 3월 16일

0 개 추천

Hi,
Thank you for your help. It works very well!
this is my matrix
0 0 143 143 152
0 0 0 0 151
0 0 0 0 143
I was trying to use indices.
[r,c,v]=(mat>0)
which gives me
1 3 143
1 4 143
1 5 152
2 5 151
3 5 143
can i rebuilt a matrix like the following using the indices
143 143 152
151
143
I'm not very familiar with matlab matrix manipulation, i'm sure i'm missing a clue somewhere !
thanks again for your help

댓글 수: 1

Walter Roberson
Walter Roberson 2011년 3월 16일
It is not possible to have a numeric matrix with empty spaces.

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

질문:

2011년 3월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by