Merge lines from a text file into another text file at specific points - merge

I have two separate text files; question.txt and answers.txt.
I would like to pull in the answers from the answer file into the question file, as shown below
BEFORE:
Question file contents:
How many sides does a triangle have?
A. 1
B. 2
C. 3
D. 4
Answer:
How many sides does a square have?
A. 1
B. 2
C. 3
D. 4
Answer:
Answer file contents:
C.
D.
AFTER:
Question file:
How many sides does a triangle have?
A. 1
B. 2
C. 3
D. 4
Answer: C
How many sides does a square have?
A. 1
B. 2
C. 3
D. 4
Answer: D

Related

Formatting numbering in MS word

Its a simple question.
I have a question with 4 options.
For example
Q1. How can you eat?
a. by mouth
b. by hand
c. by leg
d. by eyes.
I want it to format not in the above manner, but as below
Q1. How can you eat?
a. by mouth b. by hand
c. by leg d. by eyes.
How can I do that in MS word please?
You can create a 2 by 2 table. You can then hide the table grid so it appears like the formatting you specified above.
Link for creating tables: http://www.pcworld.com/article/2459947/how-to-create-and-customize-tables-in-microsoft-word.html

How to join the same matrix several times to make a big matrix in Matlab?

I have a 4x1 matrix,
A= [1;2;3;4]
I want to make B such that its size is 4x50. All the elements in the columns must contain the same elements of A. For example,
B= [1 1 1 1.... 1 1; 2 2 2 2.... 2 2; 3 3 3 3.... 3 3; 4 4 4 4.... 4 4]
In this case all the elements of A from column 1 is present in the same way in the first column of B, same for second column on B, and so on
Is there any way to form B like this from A? I was trying concatenating like below:
B= horzcat(A,A,...);
But in this case, I have to write A, 50 times. So is there any other way to get the same result?
Have you tried using repmat?
B = repmat(A, 1, 50);
repmat (which nicely stands for repeat matrix) takes a matrix and repeats itself for as many times horizontally and vertically that you want. Technically speaking, you can choose how many times you want to repeat for as many dimensions as possible as there are in your matrix. However, for our purposes here, this is a matrix which has two degrees of freedom / dimensions, so we're only considering horizontal and vertical here.
In your specific case, you want to repeat this column vector 50 times horizontally, hence the third parameter being set to 50, while you only want one copy vertically, hence the second parameter being set to 1.

How to generate all possible combinations of K instances of N objects in Matlab? [duplicate]

This question already has answers here:
Generate a matrix containing all combinations of elements taken from n vectors
(4 answers)
Closed 8 years ago.
How to generate all possible combinations of K instances of N objects in Matlab?
For example, if we have N=3 objects A, B and C, and wish to generate combinations of K=2 instances, we should get
AA
AB
AC
BA
BB
BC
CA
CB
CC
I.e. this is how figures in a number combinate.
You can use fullfact:
fullfact([3 3])
This will produce all the combinations of 3 elements in the first row and 3 elements in the second row, resulting with:
1 1
2 1
3 1
1 2
2 2
3 2
1 3
2 3
3 3
Using allcomb from matlab file exchange:
allcomb(['A','B','C'],['A','B','C'])
download
A more generalized method:
s='A':'D'
k=3
e=repmat({s},1,k)
allcomb(e{:})

Power to elements in a matrix

I have a question about being able to bring some number to the power of an element in a matrix.
I know that, if A is a matrix, then one could write A.^2 to take the square of each number in that matrix. My question is, is there any way to something like: B=2.^A, such that the resulting matrix B is the same size as A, and each element in that matrix is equal to 2 to the power of the corresponding element in A?
Thanks for any help!
You already answered yourself! Use B = 2.^A.
For example:
>> A = [1 2; 3 4]
A =
1 2
3 4
>> B = 2.^A
B =
2 4
8 16
You could also use power(2,A), which is the same thing.
Matlab is a very interactive platform, so feel free to experiment and see for yourself if something works or not. In this case your intuition was correct.

How to obtain the boolean expression from a 4 input K-Map

I noticed the 4 input K-map is read differently from a 3 input K-map.
I am assuming the A, not A, B, not B, C , not C , D and not D are located differently in a 4 input K-Map.
Can anyone explain where these locations are located on a 4 input K map?
There is article about Karnaugh map in Wikipedia. This is layout of map for 4 variables:
K-map for 4 variables.