I have a script that gets user input and creates a table. An example looks like this:
Yes No TotalPositive 15 42 57Negative 32 9 41Total 47 51 98
I want to then write a script that asks the user if they want to calculate conditional probability, and if they do, to prompt them to put in the row and column names they want to calculate the probability for
For example, P(Yes|Positive)
The user states the row and column names, so I'm finding it difficult to prompt for them in order to calculate the probability.
My script now is:
row = input('Enter number of rows: ');col = input('Enter number of columns: ');A = zeros(row + 1,col + 1); rowNames = input('Enter names of rows separated by a space: ', 's'); rowNames = strsplit(rowNames); colNames = input('Enter names of column separated by a space: ','s'); colNames = strsplit(colNames); for i = 1:row for j = 1:col str = ['Enter element in row ' num2str(i) ', col ' num2str(j) ': ']; A(i,j) = input(str); end endA;A(end,1:col) = sum(A(1:row,1:col),1);A(1:row,end) = sum(A(1:row,1:col),2);A(end,end) = sum(A(end,1:col)); T = array2table(A,'VariableNames',[colNames {'Total'}],'RowNames',[rowNames, {'Total'}]);
Best Answer