在matlab

时间:2017-12-08 15:03:25

标签: matlab

我很抱歉只有一部分代码但却不必要地复杂了。
我希望有多个问题对话框嵌入案例。 switch secim的第一个开关案例在我将最后一个选项放两次'Uc','Uc'时工作正常,除非我这样写,否则它只显示其他选项。但是当我为switch secim2的内部开关情况做同样的事情时,它会在行secim2 = questdlg('İslem?', ...上出错,当我删除第二个'Birim vektor'时,它工作正常但不会t显示了Birim vektor选项。我该如何解决这个问题?

secim = questdlg('Vektorler kac boyutlu?', ...
'Vektor', ...
'Bir','İki','Uc','Uc');
switch secim
case 'Bir'
    secim2 = questdlg('İslem?', ...
    'Vektor', ...,
    'Toplam','Fark','Skaler Carpim','Birim vektor');
switch secim2
...

1 个答案:

答案 0 :(得分:1)

如果您看到documentation,那么当您重复secim时,您在'Uc'中使用的语法是:

button = questdlg(qstring,title,str1,str2,str3,default)

正如文档中所述,default应该是str1str2str3之一,因此当您重复'Uc'时,'Uc'需要secim2 1}}作为默认值,你没有问题。

'Birim vektor'中,'Birim vektor'与三个字符串中的任何一个都不匹配,因此您会收到此警告:

  

警告:默认字符向量与任何按钮都不匹配   字符矢量名称。

如果您重复choices = {'Toplam' ,'Fark','Skaler Carpim','Birim vektor'}; SelInd = listdlg('Name','Vektor', 'PromptString','İslem?','ListString',choices,... 'CancelString', 'Default Choice', 'SelectionMode','single',... 'ListSize',[200 100]) %adjust listsize as per requirement SelInd(end+1) = 4; %Default Choice (Biriam vektor) secim2 = choices{SelInd(1)}; ,则与valid syntaxes中的任何一个都不匹配。

上述说明也在评论中指出。

如果有三个以上的字符串,请使用listdlg

Sub Export_Selection_As_Fixed_Length_File()
     ' Dimension all  variables.
    Dim DestinationFile, CellValue, Filler_Char_To_Replace_Blanks As String
    Dim FileNum, ColumnCount, RowCount, FieldWidth As Integer
    Dim sht As Worksheet

    'Below are options incase you want to change the folder where VBA stores the .txt file
    'We use ActiveWorkbook.Path in this example
    'ActiveWorkbook.Path 'the activeworkbook
    'ThisWorkbook.Path  'the workbook with the code
    'CurDir  'the current directory (when you hit File|open)


    'If a cell is blank, what character should be used instead
    Filler_Char_To_Replace_Blanks = " "

        'Check if the user has made any selection at all
        If Selection.Cells.Count < 2 Then
            MsgBox "Nothing selected to export"
            Selection.Activate
            End
        End If

    'This is the destination file name.
    DestinationFile = ActiveWorkbook.Path & "/textfile.txt"
    'Obtain next free file handle number.
    FileNum = FreeFile()

     ' Turn  error checking off.
    On Error Resume Next

     ' Attempt to open destination file for output.
    Open DestinationFile For Output As #FileNum

     ' If an error occurs report it and end.
    If Err <> 0 Then
         MsgBox "Cannot open filename " & DestinationFile
         Selection.Activate
        End
    End If

     ' Turn error checking on.
    On Error GoTo 0

     '  Loop for each row in selection.
    For RowCount = 1 To Selection.Rows.Count
                For ColumnCount = 1 To Selection.Columns.Count
                    CellValue = Selection.Cells(RowCount, ColumnCount).Text
                    If (IsNull(CellValue) Or CellValue = "") Then CellValue = Filler_Char_To_Replace_Blanks
                    FieldWidth = Cells(1, ColumnCount).Value
                    If (ColumnCount = Selection.Columns.Count) Then
                            Print #FileNum, Format$(CellValue, "!" & String(FieldWidth, "@")) & vbCrLf;
                    Else: Print #FileNum, Format$(CellValue, "!" & String(FieldWidth, "@"));
                    End If
                Next ColumnCount
         ' Start next iteration of RowCount loop.
    Next RowCount
     ' Close destination file.
    Close #FileNum
    Selection.Activate
    Workbooks.OpenText Filename:=DestinationFile
End Sub

给出:

output