Prev: DS
Next: Do NOT use virtual memory/out of memory error?
From: Mayub on 9 Aug 2010 12:29 "us " <us(a)neurol.unizh.ch> wrote in message <i3o93h$kum$1(a)fred.mathworks.com>... > "Mayub " <maahluwalia(a)hotmail.com> wrote in message <i3ntec$kgo$1(a)fred.mathworks.com>... > > "Matt Fig" <spamanon(a)yahoo.com> wrote in message <i3ikb5$lij$1(a)fred.mathworks.com>... > > > According to the help for RAND: > > > > > > Generate uniform values from the interval [a, b]. > > > r = a + (b-a).*rand(100,1); > > > > Thank you, I knew this formula from Excel, but did not recall it. Based on this I wrote the code below where the file min_max.txt contained the values I mentioned above - first row in it being min and second max. I think it is correct, because the output was OK, but please let me know your feedback. Many thanks again! > > > > A = rand(9,3); > > rowcoldata = size(A); > > nrows = rowcoldata(1,1); > > ncols = rowcoldata(1,2); > > > > MM = load('min_max.txt'); > > > > D1 = zeros(nrows, ncols); > > >> for i = 1:ncols > > D1(:,i) = A(:,i)* (MM(2, i) - MM(1, i))+ MM(1, i); % multiply the difference first, then add min > > end > > >> D = [D1]; > > save('data.txt','D','-ascii'); > > well... just a bit of a manicure > 1) no need to create extra vars D/D1, simply overwrite your A in the loop > unless, of course, you'd use your A in other places, which does not seem to be > the case... > 2) the construct D=[D1] is not necessary > > us sounds good, thanks for prompt replies! |