Matlab访问数组元素在一行

时间:2018-02-19 18:06:00

标签: arrays matlab indexing

a = 0:99
s = size(a)
disp(s(2))

最后两行可以写成一行吗?在其他语言中,我能够做f(x)[i],但Matlab似乎抱怨。

2 个答案:

答案 0 :(得分:3)

在您使用size函数的特定情况下,您可以添加一个额外的参数来指定您想要的大小尺寸,从而可以在一行中轻松完成此操作:

disp(size(a, 2));  % Displays the size of the second dimension

accessing an array element without having to store it in a local variable first的更一般情况下,事情得到a little more complicated,因为MATLAB没有与其他语言相同的索引速记。例如,Octave会允许您执行disp(size(a)(2))

答案 1 :(得分:2)

由于索引运算符的函数形式,可以在一个语句中折叠这两行,并实现<script type="text/javascript"> $(document).ready(function () { AjaxFileUpload_change_text(); }); function AjaxFileUpload_change_text() { document.getElementsByClassName('ajax__fileupload_selectFileButton')[0].innerHTML = "Abrir"; document.getElementsByClassName('ajax__fileupload_dropzone')[0].innerHTML = "Arrastre archivo aquí"; document.getElementsByClassName('ajax__fileupload_uploadbutton')[0].innerHTML = "Subir"; document.getElementById("ctl00_MainContent_AjaxFileUpload1_FileStatusContainer").innerHTML = "Seleccione archivo(s) a subir."; Sys.Extended.UI.Resources.AjaxFileUpload_Pending = "Pendiente"; Sys.Extended.UI.Resources.AjaxFileUpload_Pending = "Pendiente"; Sys.Extended.UI.Resources.AjaxFileUpload_Remove = "Quitar"; Sys.Extended.UI.Resources.AjaxFileUpload_Upload = "Subir"; Sys.Extended.UI.Resources.AjaxFileUpload_Uploaded = "Subido"; Sys.Extended.UI.Resources.AjaxFileUpload_UploadedPercentage = "{0} %"; Sys.Extended.UI.Resources.AjaxFileUpload_Uploading = "Subiendo"; Sys.Extended.UI.Resources.AjaxFileUpload_FileInQueue = "{0} archivos(s) en espera."; Sys.Extended.UI.Resources.AjaxFileUpload_AllFilesUploaded = "Completado."; Sys.Extended.UI.Resources.AjaxFileUpload_FileList = "Archivos subidos:"; Sys.Extended.UI.Resources.AjaxFileUpload_Cancelling = "Cancelando..."; Sys.Extended.UI.Resources.AjaxFileUpload_UploadError = "error"; Sys.Extended.UI.Resources.AjaxFileUpload_CancellingUpload = "Cancelando..."; Sys.Extended.UI.Resources.AjaxFileUpload_UploadingInputFile = "Subiendo: {0}."; Sys.Extended.UI.Resources.AjaxFileUpload_Cancel = "Cancelar"; Sys.Extended.UI.Resources.AjaxFileUpload_Canceled = "cancelado"; Sys.Extended.UI.Resources.AjaxFileUpload_UploadCanceled = "Subida cancelada"; Sys.Extended.UI.Resources.AjaxFileUpload_DefaultError = "Error"; Sys.Extended.UI.Resources.AjaxFileUpload_UploadingHtml5File = "Subiendo: {0}, peso: {1} bytes."; Sys.Extended.UI.Resources.AjaxFileUpload_error = "error"; } </script> subsref

# wget http://epel.mirror.net.in/epel/6/i386/epel-release-6-8.noarch.rpm
# rpm -ivh epel-release-6-8.noarch.rpm
# yum install sshpass