I keep getting an error when N > 399
So I've been trying to make a code to count the number of mutations
So I wrote my own function, countMut() that mutates a sequence for N number of times.
The problem is that whenever I set N > 399, I get this error message:
Error in if (oriAA[mutAAloc] == mutAA[mutAAloc]) { : argument is of length zero
And also I get this error sometimes when the N < 399 and sometimes I don't. I don't understand what this means... How can I fix it?
The if statement codes are here:
if (oriAA[mutAAloc] == mutAA[mutAAloc]) {
SilCount < SilCount + 1
}
Thank you for your help!
See also questions close to this topic

C++ bug in a if statement with a while statement range catch
I have this code working, for the most part.
The only problem I have is when I put in an incompatible answer after entering a compatible answer, the first time, the program terminates rather than resets.
The code takes either integers
1..4
for the answers, or1
for the flag to terminate the sequence, and thencout
the results of the counts.If not one of those five answers is entered, it is supposed to ask for an input again that is compatible.
If entering an input that is out of range once, at the start of the code, it will catch and run properly.
However, after inputting a correct answer once, if it receives an answer that is out of range or not
1
, the sequence stops rather than asking for a correct input.#include <iostream> using namespace std; int main() { int coffee = 0; int tea = 0; int coke = 0; int orangeJuice = 0; int person = 1; int choice; cout << "Please input the favorite beverage of person #" << person << ": " << endl << "Choose 1, 2, 3, or 4 from the above menu or 1 to exit the program" << endl; cin >> choice; while (choice < 1  choice > 4) { cout << "Invalid choice" << endl; cout << "Please input the favorite beverage of person #" << person << ": " << endl << "Choose 1, 2, 3, or 4 from the above menu or 1 to exit the program" << endl; cin >> choice; } while (choice != 1 && choice >= 1 && choice <= 4) { if (choice == 1) { person++; coffee++; cout << "Please input the favorite beverage of person #" << person << ": " << endl << "Choose 1, 2, 3, or 4 from the above menu or 1 to exit the program" << endl; cin >> choice; } else if (choice == 2) { person++; tea++; cout << "Please input the favorite beverage of person #" << person << ": " << endl << "Choose 1, 2, 3, or 4 from the above menu or 1 to exit the program" << endl; cin >> choice; } else if (choice == 3) { person++; coke++; cout << "Please input the favorite beverage of person #" << person << ": " << endl << "Choose 1, 2, 3, or 4 from the above menu or 1 to exit the program" << endl; cin >> choice; } else if (choice == 4) { person++; orangeJuice++; cout << "Please input the favorite beverage of person #" << person << ": " << endl << "Choose 1, 2, 3, or 4 from the above menu or 1 to exit the program" << endl; cin >> choice; } } cout << "The total number of people surveyed is " << person << ". The results are as followed." << endl; cout << "Beverage Number of Votes" << endl; cout << "**********************************" << endl; cout << "Coffee " << coffee << endl; cout << "Tea " << tea << endl; cout << "Coke " << coke << endl; cout << "Orange Juice " << orangeJuice << endl; return 0; }

Evaluating whether the output of a function falls within the 95% confidence interval of the values of the previous 3 outputs of that function
I have been trying to write a repeat function that breaks whenever its output equilibrates, meaning that it stops after a specific number of iterations, after which the function returns values that fall within the 95% confidence interval of the last 3 values returned by that function. This is example data:
a < c(1, 5) a.2 < c(9, 18) rbind(a, a.2) b < c(1, 0.5) c < c(1, 0)
This is the function I am trying out. Every computation of the values is addded to a matrix with two columns. I am using the last three columns to work out a 95% confidence intrval for the two different values. If the values fall within this interval, the function is supposed to break.
repeat { abc < sum(a * b) + c for(alpha in abc[alpha]) { if (abc[alpha] > 0) { new.abc[alpha] < (1b)a  0.2(b) } else { new.abc[alpha] < (b1)a  0.2(b) } } all.abc << matrix(ncol = 2, dimnames = list(c(),c("abc.1", "abc.2") all.abc << rbind(all.abc, new.abc) s < apply(all.abc[(length(abc[,1])  2):length(abc[,3]),], 2, sd) n < apply(all.abc[(length(abc[,1])  2):length(abc[,3]),], 2, length) error < qnorm(0.975)*s/sqrt(n) for(j in length(all.abc[j,])) { for(i in length(all.abc[,i])) { if((all.abc[j,i] < all.abc[j,i] + error * all.abc[j,i]) & (all.abc[j,i] > all.abc[j,i]  error * all.abc[j,i])) { break } } } }
However, this does not seem to work. I suppose the values of the last rows are not readily available during the execution of the function. I hope I have been clear. Tell me if I need to clarify anything. Thanks!
 How can I create an if statement on MATLAB that will replace pixels below a certain threshold to NaN?