Moving Target Defense (MTD) prevents adversaries from being able to predict the effect of their attacks by adding uncertainty in the state of a system during runtime. In this paper, we present an MTD algorithm that randomly changes the availability of the sensor data, so that it is difficult for adversaries to tailor stealthy attacks while, at the same time, minimizing the impact of false-data injection attacks. Using tools from the design of state estimators, namely, observers, and switched systems, we formulate an optimization problem to find the probability of the switching signals that increase the visibility of stealthy attacks while decreasing the deviation caused by false data injection attacks. We show that the proposed MTD algorithm can be designed to guarantee the stability of the closed-loop system with desired performance. In addition, we formulate an optimization problem for the design of the parameters so as to minimize the impact of the attacks. The results are illustrated in two case studies, one about a generic linear time-invariant system and another about a vehicular platooning problem.