Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have two arrays the first one represents the time axis with time stamp 1 min
time=[0,60,60,120,180,240,300,360,420,480,540]
and the second array represents a data values as follows
data=[18,12,12,0,7,9,6,8,12,18,0]
what im trying to do is two things:
1-I would like to fix the time axis to have 1 second time stamp
2-Perform linear Interpolation as follows:
for example i have
enter image description here
and i would like to have sth like this:
enter image description here
In case of time repetation like the repated 60 seconds the duplication should be deleted
You can remove duplicates (the first value is kept) with
time = [0,60,60,120,180,240,300,360,420,480,540];
data = [18,12,12,0,7,9,6,8,12,18,0];
[time_u unique_indeces] = unique(time);
data_u = data(unique_indeces);
clear unique_indeces;
and interpolate with
time_i = linspace(min(time), max(time), max(time) - min(time) + 1);
data_i = interp1(time_u, data_u, time_i);
I prefer linspace because I usually want to set the number of data points and not the space between points but you can also use min(time):max(time) or time(1):time(end) instead.
This code will also sort your data points by time.
Function interp1 does the job:
time=[0,60,120,180,240,300,360,420,480,540];
data=[18,15,0,7,9,6,8,12,18,0];
time_1s = 0:540;
data_interpd = interp1(time, data, time_1s);
Note: I have manually deleted the first duplicate value at time 60. If there is only one value to remove (always at same place), I think the best is to remove it by using a mask, since unique removes the second occurrence of duplicates and not first one.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I want to generate a random number with exactly 10-digits.
The random number cannot begin with zero, i.e. it must be a 10 digit number, not 10 random digits.
You need a random integer, between 1000000000 (the lowest integer with 10 digits) and 9999999999 (the highest number with 10 digits).
Note that 1000000000 = 1e9 and 9999999999 = 1e10 - 1
The random integer generation can easily achieved with randi (see the documentation here), giving it the correct minimum and maximum values...
n = randi([1e9, 1e10-1])
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
UInt62.max / 2 is represented by 0100..0000 in the memory. Add 1 and it will be 0100..0001. So, the first bit for the sign. And we take -1. But CPU thinks that it's -9 223 372 036 854 775 808. Why does it work so complexly?
You can see that it's truth because of the issue in the Swift playground: Why is UInt64 max equal -1 in Swift?
var max = UInt64.max / 2 + 1 // playground shows -1 because it treats it as Int64
Yes, in fact -1 is not represented as 1 with a sign bit, but rather as all bits set to one. This is called a "two's complement" representation, and is used in most of the modern processors.
Read more about it here:
https://en.wikipedia.org/wiki/Two%27s_complement
One of the reasons for that is that this way arithmetic operations that involve both negative and positive numbers are easier. If -1 was represented as 1 with a sign bit, and we attempted to add 1 to it in a naive way, we would get 2 with a sign bit instead of zero. With two's complement representation you can just add the numbers as if they were unsigned, and get the correct result.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
When i try to display binary notations which start with a zero in the 1st bit position, matlab discards the zero and displays only the other 7 bits. How do I display the 1st position too?
ex: when i try to display "01101111", matlab displays it as "1101111", but I need the 1st bit position value also. Can some one please help.
In Matlab, to display the bit representation of a number you need to convert it into a string with dec2bin().
So, if you have x = 111, it's binary representation is:
dec2bin(111)
ans =
1101111
which retains only the significant bits. To force an 8-bit representation use:
dec2bin(111,8)
ans =
01101111
Note, how the result will be a string. If you want to retrieve bits in numeric format, then use bitget():
bitget(111,8:-1:1)
ans =
0 1 1 0 1 1 1 1
Basically, if your need is purely visual, use dec2bin2() otherwise for manipulating bits, use the bit-wise operations functions, which accept and return numeric types.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I need matlab coding for measuring mean value of one row in a matrix of 180 by 50 rows and columns. Each time the number of row in a matrix needs to be updated to get mean value of next row (like new_row=1:1:180). Kindly respond as soon as possible
You are looking for mean().
mean(A,2)
This will give you the means of each row of matrix A.
P.S.: If you already save one row in a vector, say new_row, you can simply use:
mean(new_row)