Filter löschen
Filter löschen

How to normalize negative values in a data set/ Matrix

8 Ansichten (letzte 30 Tage)
Hello Matlab community, I have a large matrix (14680*751), each row contains data that need to be plotted(i.e., supply curve with $ values from $0to $750 on the Y axis, and carbon values on the X axis). The problem is that in each row of the matrix, there are negative values. I need to find a way to "normalize" that part of the data between the largest negative value and zero (or the first positive value basically). I attached an extract of smaller matrix B(5*20) as an example. Any suggestions are very welcome, Thank you so much, Amine
%%%%%%%Extracted data from the Big Matrix (14680*751)
%%%%%%The matrix B is extracted from the big matrix, and it is B(5*20).
%%%%%%Although some of the elements in each row are negative, they do
%%%%%%start as largely negative then start getting less negativem until
%%%%%%eventually become positive. I am trying to account for that
%%%%%%positive/marginal change or increase, because it will not make sense
%%%%%%to draw supply curves with negative values ( in microecon terms)
B=[-1.47050945378040,-1.33723076144265,-1.19710409742796,-1.05106843381422,-0.900466995312922,-0.746914945492757,-0.592176008533142,-0.438045007240660,-0.286240437664041,-0.138313835492564,0.00441798717200874,0.140914454629432,0.270426543336554,0.392489054463601,0.506895095263594,0.613658893661642,0.712972854741569,0.805163805329556,0.890652051537956,0.969915518856181;-0.841090365686416,-0.686274427020633,-0.556431695216317,-0.449093773011548,-0.361384764288333,-0.290371869645241,-0.233288673385882,-0.187655786921658,-0.151328669223115,-0.122499161299674,-0.0996709425690201,-0.0816227428265286,-0.0673679677609770,-0.0561156700226243,-0.0472353342648724,-0.0402264293996578,-0.0346928170470040,-0.0303216587858231,-0.0268662715145261,-0.0241323310815124;-2.64507912619384,-2.40991384421216,-2.17105653546875,-1.93366471136480,-1.70269068347321,-1.48245802198959,-1.27636167919902,-1.08672279348013,-0.914792168536810,-0.760868562974244,-0.624485460634832,-0.504621811603991,-0.399902903949281,-0.308771004232425,-0.229617388582594,-0.160875900735791,-0.101083038049412,-0.0489115411314220,-0.00318456064689654,0.0371234203291033;-2.95276774937878,-2.83569951619061,-2.71526650996296,-2.58659467339223,-2.44880054835685,-2.30197219410272,-2.14655597853063,-1.98323309778354,-1.81288944691232,-1.63659668475129,-1.45558765005061,-1.27122345915643,-1.08495324528020,-0.898268831972023,-0.712657273810505,-0.529554417479638,-0.350302480998157,-0.176114165152570,-0.00804508666750537,0.153024525436801;-2.05772480055009,-1.78667734692683,-1.52520993070707,-1.28101965824359,-1.05961385350071,-0.864075447044489,-0.695268465690161,-0.552316595400815,-0.433173665056002,-0.335151455327047,-0.255334769254064,-0.190866870884295,-0.139120071476573,-0.0977789501638324,-0.0648644005650677,-0.0387217871127744,-0.0179901264477179,-0.00156345495988809,0.0114488783805824,0.0217593252262164]
Y_dollars=(0:19);
%%%%%%For example plot if I plot row 1 from B
plot(B(1,:),Y_dollars)
%%%The resulting graph shows a curve increasing at an increasing rate from
%%%-1.5 to almost 2.8.... Part of the datat is between -1.5 and 0 needs to
%%%be normalized (from what I understand). ..
%%%%The challenge is that I have 14680 of these rows to derive supply
%%%%curves for, and in each row the data vary in the inetevall from
%%%%negative to zero (or to the very first positive value)
%%%The Question: can this be done using a matlab command to normalize the
%%%part of each supply curve/ data in each row to when I draw the curves
%%%they all start from zero (non-negative vlaues basically)?
  2 Kommentare
Walter Roberson
Walter Roberson am 22 Dez. 2016
You have not indicated what they need to be normalized to .
Amine Ben Ayara
Amine Ben Ayara am 22 Dez. 2016
Bearbeitet: Walter Roberson am 22 Dez. 2016
Hello Walter,
maybe I am using the wrong word. But I do need to basically adjust the negative part in each row of the entire matrix so when supply curves are drawn they start from zero ( for example in row 1 from the example matrix B; the following elements are negative, yet they get less negative until they reach zero
(-1.47050945378040 -1.33723076144265 -1.19710409742796 -1.05106843381422 -0.900466995312922 -0.746914945492757 -0.592176008533142 -0.438045007240660 -0.286240437664041 -0.138313835492564 0.00441798717200874)
so there is am increase, but when I plot the data in that 1st row as it is, the line starts with negative values, hence misleading

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Image Analyst
Image Analyst am 22 Dez. 2016
Another way:
m = magic(11) % Sample data
rowMins = min(m, [], 2)
mMins = repmat(rowMins, [1, size(m, 2)])
normalizedM = m - mMins

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 22 Dez. 2016
If the normalization is to be done over the whole matrix:
normalized_B = B - min(0, min(B(:)));
If the normalization is to be done per-row:
min_B = max(0, min(B,[], 2));
then
normalized_B = B - min_B; %requires R2016b or later
or
normalized_B = bsxfun(@minus, B, min_B); %R2007a or later
  3 Kommentare
Amine Ben Ayara
Amine Ben Ayara am 23 Dez. 2016
Again, Thank you so much Mr.Walter :)

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Two y-axis finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by