How to have an empty space in a vector for operations

44 visualizaciones (últimos 30 días)
I would like to have a vector with an blank space, not a NaN, simply a blank space. Because then I need to take the average and I would like for it to not take into account that space, for example:
x = [10 20 30 40 50 70] %(as you can see, it is missing the 60, but it has a length of 7 values)
y = [ 20 40 60 80 100 120 140] %(length of 7 values)
First, would like to know how to write that x vector.
Then I want to take the average of both vectors as:
xy_avg = mean([x,y])
so that it yeilds:
xy_avg = [ 15 30 45 60 75 120 105] %(the 120 was averaged with the blank space and the answer was just 120)
Please, I cannot have it as NaN, it has to be literally empty blank space or position, without reducing the length of the vector.
thanks in advance!

Respuesta aceptada

Matt J
Matt J el 23 de Abr. de 2022
Editada: Matt J el 23 de Abr. de 2022
I would like to have a vector with an blank space, not a NaN, simply a blank space.
There is no such thing as a "blank space" in a matrix or vector. However, inserting a NaN will do what you want if you provide an 'omitnan' flag.
x = [10 20 30 40 50 nan 70]; %(as you can see, it is missing the 60, but it has a length of 7 values)
y = [ 20 40 60 80 100 120 140]; %(length of 7 values)
mean([x;y],'omitnan')
ans = 1×7
15 30 45 60 75 120 105

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Productos


Versión

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by