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

  • Thread starter Thread starter ruijorgemoren
  • Start date Start date
  • Tags Tags
    Arrays
Click For Summary
SUMMARY

The discussion focuses on issues related to creating and using character arrays in MATLAB, specifically when attempting to store and play audio files. The user Rui encounters errors such as "Subscripted assignment dimension mismatch" and warnings about out-of-range values while trying to populate a character array with audio data from 'jose.wav' and 'antonio.wav'. The code provided demonstrates an attempt to dynamically build an array of audio samples based on user input, but fails due to improper handling of array dimensions and types.

PREREQUISITES
  • Understanding of MATLAB programming and syntax
  • Familiarity with audio processing functions in MATLAB, such as wavread and sound
  • Knowledge of character arrays and their manipulation in MATLAB
  • Basic debugging skills in MATLAB to resolve runtime errors
NEXT STEPS
  • Review MATLAB documentation on character arrays and their limitations
  • Learn about dynamic array resizing techniques in MATLAB
  • Explore the use of cell arrays for storing variable-length audio data
  • Investigate error handling and debugging methods in MATLAB to address common runtime issues
USEFUL FOR

This discussion is beneficial for MATLAB developers, audio processing engineers, and anyone looking to manipulate character arrays and audio data within MATLAB effectively.

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];
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 8 ·
Replies
8
Views
7K
  • · Replies 5 ·
Replies
5
Views
3K
Replies
2
Views
3K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K
Replies
17
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
Replies
5
Views
2K
  • · Replies 66 ·
3
Replies
66
Views
6K