I get a small project to do on scoring system. I found out that if i’m using excel to manipulated it, it definitely cause me a lot of time. I hope i get help from you guys.
A = [10 20 30 40 ...] % (1xm array)
B = [0.02; 0.04;...] % (nx1 array)
F = A/B % F should be (n x m matrix)
Z = zero (size(nxm), 3) % I'm trying to create a matrix with n x m row and 3 column)
I would like to sort F into Z(1:end), Z(1:end) respective A will be in Z(2:end) and respective B will be in Z(3:end). May i know how should i write in Matlab?
Example:
10 20 30 40 50 ...
0.02 500 1000 1500 2000 2500
0.04 250 500 750 1000 1250
0.06 166.67 333.33 500 666.67 833.33
...
output Z
166.67 10 0.06
250 10 0.04
333.33 20 0.06
....
Hope anyone here can help me. Thanks.
The thing you are looking for is either
meshgrid, orbsxfun.The meshgrid solution:
The bsxfun solution is more compact, faster, but less readable:
The trick with bsxfun is that it does singleton expansion. The inputs get repeated along each dimension having length 1, as much as needed to match the second operand.
So in the 4×4 case above you have (pseudo code):
will be expanded to (also pseudo code):
It seems you want to have it sorted by F: you can easily accomplish this by using