Working with char arrays - Solving Array Problems with Rui's Help

  • Thread starter Thread starter ruijorgemoren
  • Start date Start date
  • Tags Tags
    Arrays
AI Thread Summary
The discussion revolves around issues with creating and using character arrays in MATLAB for playing audio files. The user is attempting to load two WAV files, 'jose.wav' and 'antonio.wav', and wants to store selected audio data in an array for playback. The code provided has a few problems, particularly with how the character array 'nomes' is being populated. The user encounters errors such as "Out of range or non-integer values truncated during conversion to character" and "Subscripted assignment dimension mismatch," indicating that the assignment of audio data to the character array is not functioning as intended. The user seeks assistance in resolving these array-related issues to successfully play the selected audio files in sequence.
ruijorgemoren
Messages
2
Reaction score
0
Hi there!

I'm having problems with creating/using char arrays.

My actual code is: (I reduced the options to make it smaller here..)
Code:
int option;
int i;
fs=11025;  %frequency

%load wave files into MATLAB vectors
[jose]=wavread('jose.wav');
[antonio]=wavread('antonio.wav');

[B]nomes=char();   % ?[/B]

option=0;
i=0;
while option~=12
    
    clc;
    disp('1-Jose');
    disp('2-Antonio');
    option=input('Quais os nomes que pretende reproduzir?');
   
    i=i+1;   %I do this to guarantee that we are in the first array position on the first option choosed
    
    switch option
        
        case 1
            nome=[jose];
            [B]nomes(i)=nome;    %  ?[/B]
            i=i+1;
    
        case 2
            nome=[antonio];    
            i=i+1;
        
        case 3
    
        %etc, etc...
        
    end;
    
    
  sound(nomes,fs);  
    
end;

ok, so basicly the funtion sound will play the wav's I want.
For example, if I want to play antonio.wav and then jose.wav I would do:
Code:
sound(antonio, jose, fs)
And this is when the array appears..
My idea is to have an array and every option that is choosed will create a new position in that array with the value, for example jose or antonio.
I'm not getting this to work with this code.. Array problems?

Help please..


Thanks in advance.
Rui.
 
Physics news on Phys.org
ruijorgemoren said:
I'm having problems with creating/using char arrays.

I'm not getting this to work with this code.. Array problems?

We can't debug it if there isn't a bug...

How is it not working?
 
Code:
Warning: Out of range or non-integer values truncated during conversion to character.
> In tp3 at 54
  In run at 62
? Error using ==> run
Subscripted assignment dimension mismatch.


My line 54 in tp3.m is:
Code:
nome=[jose];
 
Back
Top