Call out specific data columns to use in function.
39 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I am just starting to learn how to use functions. I am trying to create a function that has multiple outputs and uses two vectors with data. The data in from an imported excel fine named file.xlsx. I am trying to create a function that will call on two columns (1&2 and separately, 4&10). My function will eventually plot the means in a bar graph (and include text at the top) so this is what I have so far (VERY simple) but I am not sure how to write the input in order to call out specific columns. I am assuming I will call out the specific vectors, from the data, when I actually use the function as apposed to calling out specific vectors in the function itself. any help would be appreciated.
function [m,BG] = av(x)
%
m = mean(x)
BG = bar(m)
end
0 comentarios
Respuestas (1)
Star Strider
el 7 de Oct. de 2020
I would do something like this:
function [m,BG] = av(x)
xsel = x(:,[4 10]);
m = mean(xsel);
figure
BG = bar(m);
end
save it as av.m on your MATLAB user path, then call it as:
D = readmatrix('file.xlsx');
[m,BG] = av(D);
Note that ‘BG’ will be a (1x2) bar array. If you want to re-create it later:
figure
bar(BG.XData, BG.YData)
.
12 comentarios
Slane Haltine
el 8 de Oct. de 2020
Editada: Slane Haltine
el 8 de Oct. de 2020
Star Strider
el 8 de Oct. de 2020
That appears to be correct.
However, while was off doing other things, intending to come back here in a few minutes, the file seems to have disappeared.
Ver también
Categorías
Más información sobre Startup and Shutdown en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!