I having this number generator from value 4 to 4.999 each time, I wan to make it into 2 index array such as each time the number generates the first number will store in the first index array, while the second number will store in the second index array, then the third number will store back into the first index array and repeat continuously. So lastly I able to ramp the higher value in the array index to the lower value of array index and display in numbers of samples.
I have a vi here: http://i.stack.imgur.com/902X7.png which I don't what was the correct placement. Anyone can provide me any advices?
Please let me know if you don't understand my question..
Regardless of whether you're placing data in two separate arrays or just interleaving the data, you could perform a modulo operation to swap the index or the array. Wire the Loop iteration terminal of your loop to the Quotient & Remainder function, and divide by two. Every time the remainder is zero, your index is an even number, every time it's 1, it's an odd number. You can use those results directly as the index if you're using a single, two dimensional array, or you can use it to select between two different arrays by either using a case structure, or by converting the result into a boolean value and using it as the input to a Select function.
Related
I am working with a code in MATLAB and i have to implement function y= 1-2x(t-1)
but when i try to code i get error.
How to get rid of this error?
clc
clear all
close all
t=-3:.1:3;
x=heaviside(t);
y=1-2*x(t-1)
plot(t,y)
There is a difference between evaluating a function and indexing an array, though they both use the same syntax in MATLAB.
Since x is an array, not a function, x(t-1) attempts to index into the array x, at locations t-1. However, t contains non-integer values and non-positive values. Indices in MATLAB must be between 1 and the number of elements in the array.
To shift an array by 1 to the right, you can use indexing as follows:
x([1,1:end-1])
Here, we repeat element #1, and drop the last element. There are other ways of accomplishing the same.
But, because one time unit does not correspond to one array element, since t is incremented by 0.1 every array element, this corresponds to a shift of 0.1 time units, not of 1 time unit.
To shift by one time unit, you’d have to modify the indexing above to shift the array by 10 elements. In the general case, it is posible that 1 time unit does not correspond to an integer number of array elements, for example if the increment had been 0.3 instead of 0.1. In this case, you need to interpolate:
interp1(t,x,t-1,'linear','extrap')
Here we are reading outside of the input array, and therefore need to take care of extrapolation. Hence that last argument to the function call. You can also choose to fill extrapolated values with zeros, for example.
Using a complex series of array combinations using standard Excel functions in a single formula (no VBA or UDF's involved), I've got the following result appearing mid-formula. I now need to add one final step to the formula to pull just one number out of this array:
{0,0,0,4,0,6,7...}
Using Excel formulas, how can I retrieve the first non-zero figure (in this example, 4) without any additional references to the array? Due to the complexity of the calculations it took to produce this array from the source data, I'd rather not do this twice in the same formula.
So I'm looking for functions or operators which can be applied to the array in order to yield the required result - ideally something elegant and simple. MATCH and LOOKUP fail because they require the array to be sorted. MIN fails because the lowest value is 0, not 4.
NB: The value of each non-zero figure also corresponds with its position in the array (the first would be 1, second would be 2, etc), so the first non-zero number will always be the smallest.
Try this
=1/AGGREGATE(14,6,1/{0,0,0,4,0,6,7},1)
It finds the maximum of the reciprocals ignoring the error values so the answer is 0.25. Then it takes the reciprocal of that.
I am trying to find the second lowest cost in this list. Clearly, it is $547, but when I put the formula in: =SMALL(F2:F31, 2) I get $488.00, and I am guessing this is because $488 repeats itself a number of times and so it is the second number in the list of numbers to be the smallest?
What formula should I put in to get the second smallest number, despite repeats?
What is the purpose of this? The end result? Do you seek automation or this is adhoc?
If this is adhoc, you can do:
1. copy column with numbers
2. Paste copied column into new sheet
3. Use Remove Duplicates functionality (Data tab) on this column to remove repetitions
4. Use your formula
Also, you can do this with one formula :
=SMALL(F2:F31, COUNTIF(F2:F31, MIN(F2:F31)) + 1)
As long as you only want the second smallest number, and you only have 2 digits of significant influence, you can do this fairly effectively without creating additional arrays of data, or using Array Formulas, as long as you can re-order from largest to smallest, instead of smallest to largest.
First, find the smallest number, which is simply:
=MIN(F:F)
Then, subtract 1 penny from that amount. We can now use price-is-right-rules searching to find the closest number, utilizing the next-best feature of the MATCH function, as follows:
=INDEX(F:F,MATCH(MIN(F:F)+0.01,F:F,-1))
This will take the smallest number in column F, and add .01 to it. Using -1 as the 3rd argument in the MIN function forces MIN to accept the next best alternative if this amount is not matched exactly.
Only because I figure based on your last post we are headed this way. I would as I said in that post make a unique list of all your states and counties.
Then building on #Andrew formula, which should be the one marked as correct, with COUNTIFS() as the k value in the SMALL():
=SMALL(IF(A2=DATA!A:A,IF(B2=DATA!B:B,DATA!F:F)),COUNTIFS(DATA!A:A,A2,DATA!B:B,B2,DATA!F:F,MIN(IF(A2=DATA!A:A,IF(B2=DATA!B:B,DATA!F:F))))+1)
This will give you a clean list of the second value.
Then to find the Insurance company that goes with the quote use:
=INDEX(DATA!E:E,MATCH(SMALL(IF(A2=DATA!A:A,IF(B2=DATA!B:B,DATA!F:F)),COUNTIFS(DATA!A:A,A2,DATA!B:B,B2,DATA!F:F,MIN(IF(A2=DATA!A:A,IF(B2=DATA!B:B,DATA!F:F))))+1),IF(A2=DATA!A:A,IF(B2=DATA!B:B,DATA!F:F)),0))
Put them in the second row. These are both Array formulas and will need to be confirmed with ctrl-shift-enter. Then they can be copied down as far as needed.
I'm trying to build a board of 4X4 and I'm trying to use the rand function to put random characters in the board.
I need 8 pairs of characters and I don't want to have more than one pair of the same char.
how should I do it?.. I tried a lot of variations without success.
Please help.
Not sure my answer is what you exactly want. I hope it will be helpful.
It looks like your question is more like a algorithm issue. Let's say you are trying to find 8 unique random character pairs and each pair contains two different characters.
Then you can do as following:
Get all possible characters you may use, for instance A ~ Z.
Create one array and its value is a unique character pair which has two characters you want to use. You can use a nested loop to do it.
Record how many elements you have in the array. Assume the value is N.
Use function rand() and number N to get one random number r1.
Pick up the value at position r1 of array and put it into your board.
Switch this element with the last element of array.
Use function rand() and number N-1 to get one random numbe r2. Then do step 5, 6 again.
Do it as step 4 to step 7 to get all 8 pair you want.
If you just want to get 16 unique characters, then just ignore step 2 but keep an array which has all possible characters.
If you want to some weird character, such as '$', '%', etc, then use ASC values.
I'm trying to perform math within an Excel formula to specify the end of an array. Here is a simple version of what I want to do:
A B C
1 =COUNTA(A1:A5)-1 =SUM(A1:A(1+B1))
2
3
4
5
The first column is my data array. The second column counts the number of entries in that array (so if it isn't full, it returns a value less than 5). The third column sums the array starting with the first value and ending with the last entered value. Obviously with the SUM function it doesn't matter if there are zeroes, but I am trying to use the MATCH function and I don't want it to return a zero just because there are blank entries in the array I'm looking up.
So I want to modify the information within the SUM function to produce a variable array length based on the return value of B1. I hope this is clear. Thanks for any help!
One way is to use INDEX like this
=SUM(A1:INDEX(A:A,B1+1))
you can use the range defined by
A1:INDEX(A:A,B1+1)
in other functions like MATCH
Like this?
=SUM(INDIRECT("A1:A"&(1+B1)))