Filter löschen
Filter löschen

Why does my code only come out with one result?

2 Ansichten (letzte 30 Tage)
Kylenino Espinas
Kylenino Espinas am 21 Okt. 2020
Beantwortet: Star Strider am 21 Okt. 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.

Akzeptierte Antwort

Star Strider
Star Strider am 21 Okt. 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.

Weitere Antworten (0)

Kategorien

Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by