Effacer les filtres
Effacer les filtres

Why does my code only come out with one result?

2 vues (au cours des 30 derniers jours)
Kylenino Espinas
Kylenino Espinas le 21 Oct 2020
function [siftedData, siftedMean, siftedStd, siftedNorm] = project2(rawData, categories, selectedCategory)
rawData(categories == selectedCategory) = [];
siftedData = rawData;
siftedMean = mean(rawData);
siftedStd = std(rawData)
siftedNorm = (rawData - siftedMean) ./ siftedStd;
%call with project2([1.2, 3.4, 7.6, 8.4], [1, 0, 0, 1], 1)
end
I'm supposed to have 4 outputs but when I call the function I only get the result of siftedData. Even if I use siftedData or rawData in the equations I still only get one answer.

Réponse acceptée

Star Strider
Star Strider le 21 Oct 2020
Call it as:
[siftedData, siftedMean, siftedStd, siftedNorm] = project2(rawData, categories, selectedCategory)
and all the outputs will appear in your workspace. The default behaviour for functions with several outputs is to only return the first output if there is only one assignment. If you want all of them, you need to ask for all of them.

Plus de réponses (0)

Catégories

En savoir plus sur Multidimensional Arrays dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by